ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » Publish message from a C# - .NET Application

Post new topic  Reply to topic
 Publish message from a C# - .NET Application « View previous topic :: View next topic » 
Author Message
2YanivYuzis
PostPosted: Wed Nov 14, 2007 1:06 pm    Post subject: Publish message from a C# - .NET Application Reply with quote

Newbie

Joined: 14 Nov 2007
Posts: 5

Hello.

I'm trying to send a publish message, in order to publish it with the message broker pub/sub.
I'm using MQ 6.0.2.2.
This is a C# application, using MQ client library.

I thought about two ways for doing that:
1- Send a string message to a queue, with a property that says which topic, and handle all of the RFH thing in the message broker.

But I don't know how to attach property to a string message.

2- Build a RFH2 message for a stright publish in the message broker.
But I'm stuch with the code:

// Put the next message to the queue
mqMsg = new MQMessage();
mqPutMsgOpts = new MQPutMessageOptions();

String message = "ET ISSUE";
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] bMessage = encoding.GetBytes(message);

String RFH2_STRUCID_DEFAULT = MQC.MQRFH_STRUC_ID;
int RFH2_VERSION_DEFAULT = MQC.MQRFH_VERSION_2;
int RFH2_STRUCLENGTH_DEFAULT = 36;
int RFH2_ENCODING_DEFAULT = MQC.MQENC_NATIVE;
int RFH2_CODEDCHARSETID_DEFAULT = 1208;
String RFH2_FORMAT_DEFAULT = MQC.MQFMT_RF_HEADER_2;
int RFH2_FLAGS_DEFAULT = MQC.MQRFH_NO_FLAGS;
int RFH2_NAMEVALUECCSID_DEFAULT = 1208;
String MCD_DATA_DEFAULT = "<mcd><Msd>jms_text</Msd></mcd>";
String FORMAT_MESSAGE_HRF2 = MQC.MQFMT_RF_HEADER_2;

string mcd_data = MCD_DATA_DEFAULT;
string jms_data = "<jms>jmsText</jms>";
string usr_data = "<usr><targetService>/Testing</targetService><soapAction>http://abc.ttrtrt.com/TestService</soapAction><contentType>text/xml; charset=utf-8</contentType><transportVersion>1</transportVersion><endpointURL></endpointURL></usr>";

int mcd_len = ((mcd_data.Length - 1) / 4) * 4 + 4;
int jms_len = ((jms_data.Length - 1) / 4) * 4 + 4;
int usr_len = ((usr_data.Length - 1) / 4) * 4 + 4;
int msg_len = bMessage.Length;

mcd_data += " ";
mcd_data = mcd_data.Substring(0, mcd_len);
jms_data += " ";
jms_data = jms_data.Substring(0, jms_len);
usr_data += " ";
usr_data = usr_data.Substring(0, usr_len);

mqMsg.Format = FORMAT_MESSAGE_HRF2;
mqMsg.Persistence = (int)MQC.MQPER_PERSISTENT;
mqMsg.WriteString(RFH2_STRUCID_DEFAULT);
mqMsg.WriteLong(RFH2_VERSION_DEFAULT);

mqMsg.WriteLong(RFH2_STRUCLENGTH_DEFAULT + mcd_len + jms_len + usr_len + 12);
mqMsg.WriteLong(RFH2_ENCODING_DEFAULT);
mqMsg.WriteLong(RFH2_CODEDCHARSETID_DEFAULT);
mqMsg.WriteString(RFH2_FORMAT_DEFAULT);
mqMsg.WriteLong(RFH2_FLAGS_DEFAULT);
mqMsg.WriteLong(RFH2_NAMEVALUECCSID_DEFAULT);
mqMsg.WriteLong(mcd_len);
mqMsg.WriteString(mcd_data);
mqMsg.WriteLong(jms_len);
mqMsg.WriteString(jms_data);
mqMsg.WriteLong(usr_len);
mqMsg.WriteString(usr_data);

mqMsg.Write(bMessage);

mqPutMsgOpts.Options = MQC.MQPMO_FAIL_IF_QUIESCING;
mqQueue.Put(mqMsg, mqPutMsgOpts);



Help

Thanks
Back to top
View user's profile Send private message
bower5932
PostPosted: Wed Nov 14, 2007 1:40 pm    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

What about using XMS? It uses the JMS style which I think it is easier than trying to build things yourself.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
2YanivYuzis
PostPosted: Wed Nov 14, 2007 1:58 pm    Post subject: Reply with quote

Newbie

Joined: 14 Nov 2007
Posts: 5

Thanks for the reply.
The reason for using MQ is because of existing situation.

Untill now it was a simple use:
OPEN QUEUE
WRITE QUEUE
CLOSE QUEUE.

Now we have something new, but we prefer to stay with the MQ client.
Back to top
View user's profile Send private message
bower5932
PostPosted: Wed Nov 14, 2007 2:25 pm    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

2YanivYuzis wrote:
Now we have something new, but we prefer to stay with the MQ client.


If you prefer the MQ client, you can still use XMS.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
fjb_saper
PostPosted: Wed Nov 14, 2007 3:07 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

You can send the simple message to the broker and let the broker decide to which topic to publish depending on message content and flow input queue...

You can use the MQ XMS package for .NET and build the RFH2 using the properties..., topic factory etc...

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Wed Nov 14, 2007 4:47 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Now, if people walk into that room and say "Use XMS", then they might think it's a movement...

That said, there was a sample posted about three years ago for how to build an RFH2 header using the Plain Java MQ API. I'm gonna stretch myself and say it was posted by clindsey? maybe not.

It should be reasonably adaptable to .NET - since they both use the object-oriented interface...
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
bower5932
PostPosted: Wed Nov 14, 2007 6:29 pm    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

I think the sample was jsmqput.c and it is on:

http://www-304.ibm.com/jct09002c/isv/tech/sampmq.html

However, it wasn't clindsey that wrote it....
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
2YanivYuzis
PostPosted: Wed Nov 14, 2007 10:26 pm    Post subject: Reply with quote

Newbie

Joined: 14 Nov 2007
Posts: 5

OK, Thanks a lot.
I'll try the XMS.

Hope it will be easier.
Back to top
View user's profile Send private message
2YanivYuzis
PostPosted: Wed Nov 14, 2007 10:29 pm    Post subject: Reply with quote

Newbie

Joined: 14 Nov 2007
Posts: 5

Can any one direct me to a code sample for XMS in C#?
Back to top
View user's profile Send private message
2YanivYuzis
PostPosted: Thu Nov 15, 2007 2:29 am    Post subject: Reply with quote

Newbie

Joined: 14 Nov 2007
Posts: 5

OK I'm stuc.
I get "2085" when trying to connect to the topic.

The topics is defined in the message broker,
and there's a subscriber fot this topic.


This is the source:
IConnection connection = cf.CreateConnection();

ISession session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge);

IDestination destination = session.CreateTopic("topic:\\TEST");
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Nov 15, 2007 2:32 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

What kind of queue has the subscriber defined?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Nov 15, 2007 9:00 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

2YanivYuzis wrote:
OK I'm stuc.
I get "2085" when trying to connect to the topic.

The topics is defined in the message broker,
and there's a subscriber fot this topic.


This is the source:
IConnection connection = cf.CreateConnection();

ISession session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge);

IDestination destination = session.CreateTopic("topic:\\TEST");


try IDestination destination = session.CreateTopic("topic://TEST");

_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Vitor
PostPosted: Thu Nov 15, 2007 9:12 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

DOH!!!!
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Publish message from a C# - .NET Application
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.