Author |
Message
|
bloomy |
Posted: Mon Nov 23, 2009 8:34 am Post subject: creating a MQ register subscription message using Java |
|
|
 Acolyte
Joined: 11 Feb 2009 Posts: 61 Location: Bloomington, IL USA
|
Code: |
public static void main(String args[]) throws InterruptedException {
RegisterSubscriptions objHello = new RegisterSubscriptions();
objHello.testQmgr();
try {
System.out.println("Connecting to queue manager: " + qManager);
MQQueueManager qMgr = new MQQueueManager(qManager);
//int openOptions = MQC.MQOO_OUTPUT;
int openOptions = 1040;
System.out.println("Accessing queue: " + qName);
MQQueue queue = qMgr.accessQueue(qName, openOptions);
MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_STRING;
// msg.expiry = 3000;
msg.userId = "test1";
msg.format = MQC.MQFMT_RF_HEADER_2;
String mcddata = "<mcd><Msd>jms_text</Msd></mcd> ";
String jmsdata = "<jms> </jms> ";
//String psccommand ="<psc><Command>RegSub</Command><Topic>Sport/Socccer/State/LatestScore/#</Topic><QName>TEST.TEST</QName></psc>";
try{
msg.writeString(MQC.MQRFH_STRUC_ID); //StrucID
msg.writeInt4(MQC.MQRFH_VERSION_2); //Version
msg.writeInt4(MQC.MQRFH_STRUC_LENGTH_FIXED_2 + 32 + 16); //StrucLength
msg.writeInt4(MQC.MQENC_NATIVE); //Encoding
msg.writeInt4(MQC.MQCCSI_DEFAULT); //CodedCharSetID
msg.writeString(MQC.MQFMT_NONE); //Format
msg.writeInt4(MQC.MQRFH_NO_FLAGS); //Flags
msg.writeInt4(MQC.MQCCSI_DEFAULT); //NameValueCCSID
msg.writeInt4(32);//NameValueLength <mcd>
msg.writeString(mcddata); //NameValueData <mcd>
msg.writeInt4(16);//NameValueLength <mcd>
msg.writeString(jmsdata); //NameValueData <mcd>
// msg.writeInt4(200);//NameValueLength <jms>
// msg.writeString(psccommand); //NameValueData <usr>
// msg.writeUTF("TEST"); //Actual MESSAGE data
// msg.replyToQueueName = "BANG.QR";
// msg.replyToQueueManagerName="MYS.SEND";
// msg.report = MQC.MQRO_EXCEPTION_WITH_FULL_DATA;
}catch(Exception e){
e.printStackTrace();
} |
Trying to create aregister subscription message using Java.
I have the mcd set with length 32 which is a multiple of 4.
Also the jms tag that is 16 and that is also multiple of 4.
When i run this i get " Invalid length in RFH2 variable area - data skipped"
tha data is "jms>" it is assuming everything befor "jms>" as part of the mqrfh2 header? I am not sure how to get this to work . There are no examples specific to setting the psc folder in infocenter or anywhere else.
Spent too much time on this. Can you guys shed some light please, point me in the right direction, an example maybe. Thanks. |
|
Back to top |
|
 |
jugo |
Posted: Mon Nov 23, 2009 9:27 am Post subject: |
|
|
Novice
Joined: 17 Nov 2009 Posts: 13
|
This isn't my area of speciality, but since no-one else has said anything, here are my thoughts: it wouldn't surprise me if there were some subtleties to the writeString() method regarding padding with null characters and/or character conversion. You could try using the getDataOffset() or getMessageLength() methods to work out what (if any) padding is added. I notice there are also the writeBytes() and writeChars() methods that will take strings. They may handle padding and character conversion differently.
When writing applications in Java to subscribe, most people typically use JMS, which is a much easier interface. I'm guessing that you're using the MQ API because you have a need to, but if not then take a look at one of the JMS samples such as JmsConsumer (it's in my MQ 7.0 installation), which you may find much easier. |
|
Back to top |
|
 |
bloomy |
Posted: Mon Nov 23, 2009 11:23 am Post subject: |
|
|
 Acolyte
Joined: 11 Feb 2009 Posts: 61 Location: Bloomington, IL USA
|
I just want to create a register susbcription message and put it on the system.broker.control.queue so that the broker will register it as a subscriber. Can i do this with JMS? Should i look into creating a JMS subscriber and not worry about the MQRFH2? |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Nov 23, 2009 3:04 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
bloomy wrote: |
I just want to create a register susbcription message and put it on the system.broker.control.queue so that the broker will register it as a subscriber. Can i do this with JMS? Should i look into creating a JMS subscriber and not worry about the MQRFH2? |
JMS will handle the MQRFH behind the scenes for you.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
bloomy |
Posted: Tue Dec 01, 2009 3:27 pm Post subject: |
|
|
 Acolyte
Joined: 11 Feb 2009 Posts: 61 Location: Bloomington, IL USA
|
Using
DEF TCF(MYTCF) TRANSPORT(CLIENT) QMANAGER(QMGR1) HOST(***) PORT(1414) CHANNEL(SYSTEM.DEF.SVRCONN) BROKERQMGR(QMGR1) BROKERSUBQ(TESTQ) BROKERVER(V2) BROKERCONQ(SYSTEM.BROKER.CONTROL.QUEUE) BROKERCCSUBQ(SYSTEM.JMS.ND.CC.SUBSCRIBER.QUEUE) BROKERPUBQ(SYSTEM.BROKER.CONTROL.QUEUE) SUBSTORE(BROKER)
trying to use JMS to register subscription with message broker. I tried using BROKERVER(V2) to specify that i am using message broker. But when i run the JMSPubSub sample that comes with MQ, it is throwing the below error.
Exception in thread "main" javax.jms.JMSException: MQJMS3021: Invalid subscriber queue prefix: TESTQ
it is not erroing out if i specify the queue name as SYSTEM.JMS.ND.TESTQ but that doesnt seem to register a subscription with the broker.
I thought the SYSTEM.JMS prefix was only needed when i use the MQ broker.
How can i get a JMS program to work to register a subscription with message broker? Pheew!!! been working on this for 3 days now. Any help? |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Dec 02, 2009 8:59 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
bloomy wrote: |
Using
DEF TCF(MYTCF) TRANSPORT(CLIENT) QMANAGER(QMGR1) HOST(***) PORT(1414) CHANNEL(SYSTEM.DEF.SVRCONN) BROKERQMGR(QMGR1) BROKERSUBQ(TESTQ) BROKERVER(V2) BROKERCONQ(SYSTEM.BROKER.CONTROL.QUEUE) BROKERCCSUBQ(SYSTEM.JMS.ND.CC.SUBSCRIBER.QUEUE) BROKERPUBQ(SYSTEM.BROKER.CONTROL.QUEUE) SUBSTORE(BROKER)
trying to use JMS to register subscription with message broker. I tried using BROKERVER(V2) to specify that i am using message broker. But when i run the JMSPubSub sample that comes with MQ, it is throwing the below error.
Exception in thread "main" javax.jms.JMSException: MQJMS3021: Invalid subscriber queue prefix: TESTQ
it is not erroing out if i specify the queue name as SYSTEM.JMS.ND.TESTQ but that doesnt seem to register a subscription with the broker.
I thought the SYSTEM.JMS prefix was only needed when i use the MQ broker.
How can i get a JMS program to work to register a subscription with message broker? Pheew!!! been working on this for 3 days now. Any help? |
The SYSTEM.JMS prefix is mandatory as specified in the doc.
There is nothing to prevent you from making the SYSTEM.JMS.XXX queue an Alias queue pointing to your TESTQ.
If you don't want to use JMS pub/sub but still want to retrieve your subscription messages in JMS you need to consume them from a queue.
See as well the pub/sub manual in V7
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|