Author |
Message
|
peterw686 |
Posted: Fri Jan 23, 2004 3:01 pm Post subject: sending msg to cluster queue by using java class |
|
|
Acolyte
Joined: 26 Sep 2002 Posts: 73
|
Hi,
Is that a way to send message to a cluster queue by using java class without knowing the channel?
I know if I send a message to a local or remote queue by using java class, I need to know the host, port, queue name, queue manager name, channel name, user/password.
For cluster queue, it normally only defines cluster sender and receiver channel, in this case, how can I send message to the queue with out know channel name?
(Full) (Full) (none)
QM1<--------->QM2<------------>QM3<- a cluster
RqstQ ------- RqstQ ---------- RplyQ
App 1 App 1
In the example above, how can send message to RplyQ by using java class in App1
( I need to use this way to specify the message ID)
Thanks. |
|
Back to top |
|
 |
Michael Dag |
Posted: Fri Jan 23, 2004 3:32 pm Post subject: |
|
|
 Jedi Knight
Joined: 13 Jun 2002 Posts: 2607 Location: The Netherlands (Amsterdam)
|
Peter,
for the put there is no difference, you connect to you local Qmgr in binding mode or to a remote using channels. Where the ClusterQ is is not important as long as it is known to the Qmgr you are connecting to.
For the get of return message, you can not get from a ClusterQ unless it is local! So your responding app need to put the message to a replyToQ that is also Clustered but local on your side.
I hope this makes sense it is kinda late out here...
Michael |
|
Back to top |
|
 |
peterw686 |
Posted: Mon Jan 26, 2004 8:32 am Post subject: |
|
|
Acolyte
Joined: 26 Sep 2002 Posts: 73
|
Thanks, Michael,
I tried on NT and everything is fine.
I did the same test on UNIX but got nullpoint exception. Could you help me on this one?
The test case is :
QM1----------------------------QM3 <----- in a cluster
Q1 ------------------------------ Q2 <------ cluster queue
My App runs on the same machine as QM1 and it tried to send a message to Q2 via QM1.
The MQEnvironment setting is :
Code: |
MQEnvironment.hostname = hostName; // host name of QM1
MQEnvironment.channel = channel; // using SYSTEM.DEF.SVRCONN
MQEnvironment.port = port; // the QM1's listen port
MQEnvironment.userID = user; // null
MQEnvironment.password = password; // null
MQEnvironment.properties.put( MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES_CLIENT);
|
The java code is :
Code: |
// create queue manager
mqManager = new MQQueueManager(queueManager);
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_SET_IDENTITY_CONTEXT;
logger.debug("Try to access the Queue. "+queueName);
// specify the queue that wish to open
queue = mqManager.accessQueue(queueName, openOptions);
// get the message
MQMessage mqMsg = new MQMessage();
// set the User name
mqMsg.userId = user;
// set the application name
mqMsg.putApplicationName = "CSG";
// set application type
mqMsg.putApplicationType = MQC.MQAT_JAVA;
// set message format
mqMsg.format = MQC.MQFMT_STRING;
// set message timestamp
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date(System.currentTimeMillis()));
mqMsg.putDateTime = cal;
// set the encoding
if( qInfo.getEncoding() > 0 ){
mqMsg.encoding = qInfo.getEncoding();
mqMsg.characterSet = qInfo.getCCSID();
}else{
mqMsg.encoding=MQC.MQENC_NATIVE;
}
// set the message ID
if( messageID != null ){
mqMsg.messageId = messageID.getBytes();
}
// set the correlationID
if( correlationID != null ){
mqMsg.correlationId = correlationID.getBytes();
}
// set report options
int reportOption = MQC.MQRO_PASS_MSG_ID | MQC.MQRO_PASS_CORREL_ID;
mqMsg.report = reportOption;
logger.debug("The Message report option is "+ reportOption);
// set reply options
String replyToQ = qInfo.getReplyToQ();
String replyToQMGR = qInfo.getReplyToQMGR();
if( replyToQ != null && replyToQ.trim().length() > 0 ){
mqMsg.replyToQueueName = replyToQ;
}
if( replyToQMGR != null && replyToQMGR.trim().length() > 0 ){
mqMsg.replyToQueueManagerName = replyToQMGR;
}
logger.debug("The replyToQ and replyToQMGR are ["+replyToQ+"] ["+replyToQMGR+"]");
// put XML message into it
mqMsg.writeString(strMsg);
// specify the message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_SET_IDENTITY_CONTEXT | MQC.MQPMO_SYNCPOINT;
// put message to the queue
queue.put(mqMsg, pmo);
// commit
mqManager.commit();
byte[] msgID = mqMsg.messageId;
|
The exception throws on the call of
Code: |
mqManager = new MQQueueManager(queueManager); |
The error is "
Quote: |
java.lang.NullPointerException
at com.ibm.mq.ClientConnectionRequestInfo.equals(ClientConnectionRequestInfo.java:239)
at com.ibm.mq.ManagedConnectionStore$Tuple.equals(ManagedConnectionStore.java:148)
at java.util.Hashtable.get(Hashtable.java:318)
at com.ibm.mq.ManagedConnectionStore.chooseOne(ManagedConnectionStore.java:110)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:124)
at com.ibm.mq.MQQueueManager.obtainBaseMQQueueManager(MQQueueManager.java:682)
at com.ibm.mq.MQQueueManager.construct(MQQueueManager.java:620)
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:393)
at com.cgi.cs.gateway.mqjms.MQClientSender.send(MQClientSender.java:75)
at com.cgi.cs.gateway.mqjms.MQClientSender.send(MQClientSender.java:31)
at com.cgi.cs.gateway.mdb.MVSToEquifaxBean.onMessage(MVSToEquifaxBean.java:116)
at weblogic.ejb20.internal.MDListener.execute(MDListener.java:356)
at weblogic.ejb20.internal.MDListener.transactionalOnMessage(MDListener.java:290)
at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:271)
at com.ibm.mq.jms.MQQueueReceiver.receiveAsync(MQQueueReceiver.java:861)
at com.ibm.mq.jms.contact admin.run(contact admin.java:401)
at java.lang.Thread.run(Thread.java:479) |
The only difference between those two test cases is that on UNIX the application code is executed inside of a MDB's onMessage(). The MDB listens to another queue on the same machine.[/code] |
|
Back to top |
|
 |
peterw686 |
Posted: Mon Jan 26, 2004 12:09 pm Post subject: |
|
|
Acolyte
Joined: 26 Sep 2002 Posts: 73
|
I checked the weblogic server on unix and found it got some JVM error. I remember that some place on the internet mentioned that MQ java has bugs which has conflict with JVM.
I set the JMV mem regs to 200m and restart server. It works fine although I don't know the reason. |
|
Back to top |
|
 |
techno |
Posted: Fri Jan 30, 2004 4:58 pm Post subject: JMS and Cluster |
|
|
Chevalier
Joined: 22 Jan 2003 Posts: 429
|
How do I connect to a cluster-q in a cluster? Is it same as a regular one? In regular api, we need qmgr and q. In cluster, I should not be mentioning qmgr' name ( I think), so that it makes the connection to available qmgr.
Pls throw some light on this.
Thanks. |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Feb 04, 2004 8:28 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
If you are using JMS, you need to specify a connection factory that is the queue manager that you wish to connect to. You then need to define a queue that has your cluster queue's name in it and does NOT have the qmgr field filled in. If you do fill in the qmgr field, it will prevent you from getting to any queue in the cluster. Is this what you are asking? |
|
Back to top |
|
 |
techno |
Posted: Wed Feb 04, 2004 9:46 pm Post subject: |
|
|
Chevalier
Joined: 22 Jan 2003 Posts: 429
|
yes, could u provide me a snippet of code?
thanks |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Feb 05, 2004 5:34 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
If you are using JMS, there isn't any actual code. You'd define a qcf similar to:
def qcf(myQCF) qmgr(my.qmgr)
and a queue similar to:
def q(myQ) queue(MY.QUEUE)
You wouldn't add the 'qmgr(my.qmgr)' onto the 'def q'. |
|
Back to top |
|
 |
shantha |
Posted: Tue Feb 10, 2004 8:57 pm Post subject: |
|
|
Apprentice
Joined: 11 Dec 2003 Posts: 41
|
How do you do the same thing using MQ API.
I don't want to give the qm NAME.IS it possible to connect without giving the QM name
Please help me
Shantha |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Feb 11, 2004 6:27 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
My earlier appends were related to JMS and not the base MQ Java. I saw that you were using MDBs, and I assumed JMS. Sorry for the confusion.
As far as connecting/not connecting to a qmgr, you have to connect to a qmgr. However, you can connect using an empty string which will connect you to the default qmgr:
qMgr = new MQQueueManager("");
However, if you don't have a default qmgr, you'll end up with a 2059. |
|
Back to top |
|
 |
|