Author |
Message
|
sanks |
Posted: Sun Nov 06, 2005 11:23 pm Post subject: publish a topic using MQI |
|
|
Apprentice
Joined: 21 Mar 2005 Posts: 27
|
It is very very urgent.
Can any body tell me without using JMS how can I publish a topic in a Queue using MQAPI?
Any code base will be very much helpfull.
Thanks in advance.
sanks |
|
Back to top |
|
 |
wschutz |
Posted: Mon Nov 07, 2005 3:11 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
You can create a publication message using any language (althougt its easer in some than in others), C, C++, C#, JAVA, PERL, TAL, Assembler, COBOL.....
What language(s) are you using? _________________ -wayne |
|
Back to top |
|
 |
sanks |
Posted: Mon Nov 07, 2005 4:30 am Post subject: |
|
|
Apprentice
Joined: 21 Mar 2005 Posts: 27
|
Thanks for your response.
I am using JAVA.
It will nice of you if you give me some code base or Pseudo code using MQI.
Waiting for your valuable reply.
Sanks |
|
Back to top |
|
 |
bower5932 |
Posted: Mon Nov 07, 2005 4:38 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
Take a look at the soccer sample that ships with the product. It is written in C, but it should show you what you'll need to do with the RFH2 header. |
|
Back to top |
|
 |
sanks |
Posted: Mon Nov 07, 2005 5:07 am Post subject: |
|
|
Apprentice
Joined: 21 Mar 2005 Posts: 27
|
I have the following codebase that set the RFH2 header.
I have started brkr using strmqbrkr command.
I run the code which put the message (having RFH2 header end with my message) in SYSTEM.BROKER.DEFAULT.STREAM.
How can I test that the message get published with specified topic (Stock) in queue (Q1)?
Please let me know If I am doing any thing wrong.
Code: |
public MQMessage buildRFH2Header(MQMessage msg) throws IOException {
System.out.print("Start setting RFH2 Header in the MQMD..");
String pubCommand = new String();
pubCommand =
"<psc><Command>Publish</Command><Topic>Stock</Topic>"
+ "<QMgrName>TestQM</QMgrName><QName>Q1</QName></psc>";
int folderLength = pubCommand.length();
MQMessage theMsg = msg;
theMsg.clearMessage();//clear message --SUPAL
theMsg.putApplicationName = APPLICATION_NAME; //--SUPAL
theMsg.format = MQC.MQFMT_RF_HEADER_2; // Msg Format
theMsg.writeString(MQC.MQRFH_STRUC_ID); // StrucId
theMsg.writeInt4(MQC.MQRFH_VERSION_2); // Version
theMsg.writeInt4(MQC.MQRFH_STRUC_LENGTH_FIXED_2 + folderLength + 4);
//4) + rf); // StrucLength
theMsg.writeInt4(MQC.MQENC_NATIVE); // Encoding
theMsg.writeInt4(MQC.MQCCSI_DEFAULT); // CodedCharacterSetId
theMsg.writeString(MQC.MQFMT_NONE); // Format (content)
theMsg.writeInt4(MQC.MQRFH_NO_FLAGS); // Flags
theMsg.writeInt4(1208); // NameValueCCSID = UTF-8
theMsg.writeInt4(folderLength);
theMsg.writeString(pubCommand);
theMsg.writeString("begin My Message");
System.out.println("Done");
return theMsg;
} |
[/quote] |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Nov 07, 2005 5:10 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You have to have a subscriber to test your publisher. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
sanks |
Posted: Mon Nov 07, 2005 5:20 am Post subject: |
|
|
Apprentice
Joined: 21 Mar 2005 Posts: 27
|
I am agreeing with you.
But with out subscriber I can see (by WMQ Explorer) the topic message in the queue on which the topic has been published.Right?
In my scenario when I put the message (RFH2 headed) into "SYSTEM.BROKER.DEFAULT.STREAM", broker (which is already running ) should route this message in the topic queue namely "Q1".
Am I correct? |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Nov 07, 2005 5:26 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
sanks wrote: |
I am agreeing with you.
But with out subscriber I can see (by WMQ Explorer) the topic message in the queue on which the topic has been published.Right? |
I don't think so.
But I could be wrong.
Does it work?
I think that all of the MQ Brokers only publish messages for which there is at least one registered subscriber. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
sanks |
Posted: Mon Nov 07, 2005 5:42 am Post subject: |
|
|
Apprentice
Joined: 21 Mar 2005 Posts: 27
|
One think I need to clearify.
To publish a topic in a queue thru broker should I need to put RFH2 headed message to SYSTEM.BROKER.DEFAULT.STREAM or SYSTEM.BROKER.CONTROL.QUEUE?
May be I am doing wrong from technical MQ pub/sub broker perspective.
What I did is basicaly
1> Start broker by strmqbrk command
2>made a mssage with RFH2 header with publish command like
pubCommand =
"<psc><Command>Publish</Command><Topic>Stock</Topic>"
+ "<QMgrName>TestQM</QMgrName><QName>Q1</QName></psc>";
3>Put this message into SYSTEM.BROKER.DEFAULT.STREAM.
Is there any thing i need to follow?
Please help me. |
|
Back to top |
|
 |
bower5932 |
Posted: Mon Nov 07, 2005 5:50 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
You might want to take a closer look at the soccer sample. It will answer all of your questions about where you should be putting which messages. You also need to get a subscriber up and running so that you can confirm that your publisher is actually working. There is a jms subscriber (mqjmssub.java) at:
http://www.developer.ibm.com/isv/tech/sampmq.html
You can use this for the subscriber half of your environment. |
|
Back to top |
|
 |
sanks |
Posted: Mon Nov 07, 2005 6:04 am Post subject: |
|
|
Apprentice
Joined: 21 Mar 2005 Posts: 27
|
Some of my ovservation(I am yet to run the subscriber)
1>I put message (with topic queue and topic name specified as pucommand in RFH2 header) default broker stream queue SYSTEM.BROKER.DEFAULT.STREAM. (Question: Is it the correct broker queue to publish a topic?)
2>I have seen thru MQ Explorer the message is there.
In this stand point I want to make a Queue to be subscribed on that topic.
How can I do that?
Please help. Should I need to use rfhutil.exe? |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Nov 07, 2005 6:10 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Okay, you see a message sitting on SYSTEM.BROKER.DEFAULT.STREAM.
This is because you put it there, not because it's been published.
The list of the broker queues (at least the system ones) is here.
You publish messages by putting them on the SYSTEM.BROKER.CONTROl.QUEUE, not the DEFAULT.STREAM.
Then you can register a subscriber. Then messages you publish will show up. _________________ I am *not* the model of the modern major general.
Last edited by jefflowrey on Mon Nov 07, 2005 7:10 am; edited 1 time in total |
|
Back to top |
|
 |
bower5932 |
Posted: Mon Nov 07, 2005 7:08 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I thought you put all command messages to the SYSTEM.BROKER.CONTROL.QUEUE and you put all publication messages to the SYSTEM.BROKER.DEFAULT.STREAM.
You could also check to see if anybody has your STREAM queue open for input. I'm beginning to think that you probably don't even have the broker running.
I'd also strongly suggest that you try running the soccer sample. It will confirm that you have an environment that is setup correctly. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Nov 07, 2005 1:57 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
And as you're going with Java I'd use JMS instead of base Java...
It makes things just so much easier in the PUB/SUB environment.
I'd think that the time spent creating the RFH header in base is greater than the time needed in JMS as this package has already been optimized for that purpose.
Enjoy  |
|
Back to top |
|
 |
sanks |
Posted: Mon Nov 07, 2005 10:17 pm Post subject: |
|
|
Apprentice
Joined: 21 Mar 2005 Posts: 27
|
hi fjb_saper
I need to set some MQMD properties for content base filtering when publishing a topic. I think I couldn't able to do the same by JMS.
hi bower5932
what do you mean by control command and publish command.. how they differ ? can you give a code snippet? I have written the java code based on the Soccer example , I need to use a Broker only can support version 1 and RFH1 msg type.
I have seen a strange behavour while putting message to SYSTEM.BROKER.DEFAULT.STREAM. The message I put is immediately get consumed by Broker.But after that nothing happens. Though I have created a subscriber Queue.I could not find any message in a subscriber Queue.
The message I have put in the queue is build like following:
In the buildRFHHeader() function I have created the publish command string. I have a doubt whether this command is correct for RFH1 version.
Code: |
static void main()
{
MQMessage msg = buildRFHHeader(MQMessage msg);
msg.writeString(myMessage);
MQQueue q =
m_qMgr.accessQueue(
"SYSTEM.BROKER.DEFAULT.STREAM",
openOptions,
null,
null,
null);
q.put(msg, pmo);
}
public MQMessage buildRFHHeader(MQMessage msg) throws IOException {
String pubCommand = new String();
pubCommand =
"<psc><Command>Publish</Command><Topic>SLAM/ALL</Topic>"
+ "<QMgrName>SLAMQM</QMgrName><QName>SLAM/ALL</QName></psc>";
int folderLength = pubCommand.length();
MQMessage theMsg = msg;
theMsg.format = MQC.MQFMT_RF_HEADER_1; // Msg Format
theMsg.writeString(MQC.MQRFH_STRUC_ID); // StrucId
theMsg.writeInt4(MQC.MQRFH_VERSION_1); // Version
theMsg.writeInt4(MQC.MQRFH_STRUC_LENGTH_FIXED_1 + folderLength + 4);
theMsg.writeInt4(MQC.MQENC_NATIVE); // Encoding
theMsg.writeInt4(MQC.MQCCSI_DEFAULT); // CodedCharacterSetId
theMsg.writeString(MQC.MQFMT_NONE); // Format (content)
theMsg.writeInt4(MQC.MQRFH_NO_FLAGS); // Flags
theMsg.writeInt4(folderLength+4); // NameValueString
theMsg.writeInt4(folderLength);
theMsg.writeString(pubCommand);
return theMsg;
}//buildRFHHeader |
|
|
Back to top |
|
 |
|