|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
JMS Program output different from MQJExplorer and rfhutilc |
« View previous topic :: View next topic » |
Author |
Message
|
nporwal |
Posted: Wed Apr 23, 2008 10:00 am Post subject: JMS Program output different from MQJExplorer and rfhutilc |
|
|
Newbie
Joined: 21 Apr 2008 Posts: 2
|
I am using MQ to connect to the mainframe.
If I send the message over a program such as MQJExplorer, I get the return message okay.
If I send the message over a java program using jms, I get a response from the mainframe that the message it received was too long.
I can't figure out what I am doing wrong. Can you have a look below and let me know what I am missing?
The length of the Message is around 650, its much less then the max size on the mainframe.
Thanks.
Code: |
import com.ibm.mq.jms.*;
import javax.jms.*;
import java.util.*;
public class MQJMSClient {
public static void main(String[] args) throws JMSException {
System.out.println("MQJMS2/MQJMSClient");
String strChannel = "JAVA.CHANNEL";
String strHostName = "TESTSYSTEM01";
int iPort = 1414;
String strQueueManager = "SIEBEL8SIT";
String strQueuePut = "UNIX.APPLICATION.SEND";
String strQueueGet = "UNIX.APPLICATION.RECEIVE";
String strRequest = "SOMEXMLMESSAGE";
int iTransportType = JMSC.MQJMS_TP_CLIENT_MQ_TCPIP;
String strResponse = null;
com.ibm.mq.jms.MQQueueConnectionFactory fact = null;
javax.jms.QueueConnection qConnection = null;
javax.jms.QueueSession qSession = null;
javax.jms.Queue requestQueue = null;
javax.jms.Queue responseQueue = null;
javax.jms.QueueReceiver qReceiver = null;
javax.jms.QueueSender qSender = null;
javax.jms.TextMessage requestMessage = null;
javax.jms.TextMessage responseMessage = null;
String strJMSMessageID;
String strFilter;
try{
System.out.println("Starting");
fact = new MQQueueConnectionFactory();
System.out.println("Connection Factory created");
fact.setChannel(strChannel);
System.out.println("Factory Channel set to:"+strChannel);
fact.setHostName(strHostName);
System.out.println("HostName set to:" + strHostName);
fact.setPort(iPort);
System.out.println("Port Set to:" + iPort);
fact.setQueueManager(strQueueManager);
System.out.println("Queue Manager set to:" + strQueueManager);
fact.setTransportType(iTransportType);
System.out.println("Transport Type set to:" + iTransportType);
qConnection = fact.createQueueConnection();
System.out.println("Connection Created");
qConnection.start();
System.out.println("Connection Started");
boolean transacted = false;
qSession = qConnection.createQueueSession(transacted,Session.AUTO_ACKNOWLEDGE);
System.out.println("Session Created");
requestQueue = null;
requestQueue = qSession.createQueue(strQueuePut);
System.out.println("Request Queue Created");
responseQueue = null;
responseQueue = qSession.createQueue(strQueueGet);
System.out.println("Response Queue Created");
requestMessage = qSession.createTextMessage(strRequest);
System.out.println("Message Created");
System.out.println("The length of the message is:"+strRequest.length());
requestMessage.setJMSType("MessageText");
qSender = qSession.createSender(requestQueue);
System.out.println("Queue Sender Created");
qSender.send(requestMessage);
System.out.println("Message Sent");
strJMSMessageID = requestMessage.getJMSMessageID();
System.out.println("JMS Message:" + strJMSMessageID);
strFilter = "JMSCorrelationID = '" + strJMSMessageID + "'";
System.out.println("Receive Filter set to:" + strFilter);
qReceiver = qSession.createReceiver(responseQueue, strFilter);
System.out.println("Queue Receiver Created");
responseMessage = (TextMessage)qReceiver.receive();
System.out.println("Response Message Type:" + responseMessage.getJMSType());
System.out.println("Received Message");
strResponse = responseMessage.getText();
System.out.println("Created Response");
System.out.println("-----------");
System.out.println("Request:");
System.out.println(strRequest);
System.out.println("-----------");
System.out.println("Response:");
System.out.println(strResponse);
System.out.println("Completed");
}
catch (Exception e){
e.printStackTrace();
}
finally{
if (qReceiver != null) {
qReceiver.close();
qReceiver = null;
}
if (qSender != null) {
qSender.close();
qSender = null;
}
if (requestQueue != null) {
requestQueue = null;
}
if (responseQueue != null) {
responseQueue = null;
}
if (requestMessage != null) {
requestMessage = null;
}
if (responseMessage != null) {
responseMessage = null;
}
if (qSession != null) {
qSession.close();
qSession = null;
}
if (qConnection != null) {
qConnection.close();
qConnection = null;
}
if (fact != null) {
fact = null;
}
System.out.println("Exit");
}
}
}
|
|
|
Back to top |
|
 |
bower5932 |
Posted: Wed Apr 23, 2008 10:04 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Apr 23, 2008 3:02 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
The problem is here:
Quote: |
responseQueue = qSession.createQueue(strQueueGet); |
This is what you need:
Code: |
String myqueue="queue:///"+strQueueGet+"?targetClient=1";
qSession.createQueue(myqueue); |
Don't remember, you might have to transform the String to an URI first...
The url in the preceding post has all the explanations as to why....
Anyways get with the program and use JNDI.
So in JNDI you set your target client to 'MQ'.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
nporwal |
Posted: Wed Apr 23, 2008 5:02 pm Post subject: |
|
|
Newbie
Joined: 21 Apr 2008 Posts: 2
|
Thanks bower5932 and fjb_saper for your suggestion. I read up about the Target Client and was able to make this work. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|