Author |
Message
|
ndengland |
Posted: Tue Jul 28, 2009 7:43 am Post subject: JMS client recieving reply from non-JMS producer |
|
|
Newbie
Joined: 28 Jul 2009 Posts: 6
|
Hello,
I have a JMS client (a session EJB) which is running on WAS and putting a request message on an MQ queue. The consumer reading the request is a non JMS client. I have successfully been able to create the request flow, where the JMS message is sent to the queue and picked up by the non-JMS (MQ API) client.
[On the WAS admin console, I have configured the destination (request) queue as Target Client = MQ.]
My problem is on the reply side. The non-JMS client is putting messages on the reply queue, but my JMS client (the EJB) does a recieve() that is not returning anything.
At first, I thought I might have the wrong filter, but I'm still not getting the messages on the queue when I recieve() with no filters.
Code: |
qReceiver = session.createConsumer(replyQueue);
System.out.println("Waiting to recieve reply...");
replyMessage = qReceiver.receive(timeout);
|
I am able to look at the messages using MQ Explorer utility, but I know I must be missing something in my configuration. Any idea what I am missing?
I will eventually need to read the queue using a filter on the CorrelId but right now the JMS client isn't getting any messages yet.
-Nate |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jul 28, 2009 9:44 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Did you start the receiver?
It doesn't look like you did. |
|
Back to top |
|
 |
ndengland |
Posted: Tue Jul 28, 2009 10:06 am Post subject: |
|
|
Newbie
Joined: 28 Jul 2009 Posts: 6
|
Here is a code snippet of the lookups/connections:
Code: |
initContext = new InitialContext();
factory = (ConnectionFactory) initContext.lookup(connectionFactoryJNDIName);
requestQueue = (Destination) initContext.lookup(requestQueueJNDIName);
replyQueue = (Destination) initContext.lookup(replyQueueJNDIName);
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
Here is the full code of my method:
Code: |
private Message getReply(Session session, Destination replyQueue, String filter, long timeout)
throws JMSException
{
MessageConsumer qReceiver = null;
Message replyMessage = null;
try
{
UserTransaction ut = this.mySessionCtx.getUserTransaction();
ut.begin();
qReceiver = session.createConsumer(replyQueue);
System.out.println("Waiting to recieve reply...");
replyMessage = qReceiver.receive(timeout);
if (replyMessage != null)
{
System.out.println("JMSCorrelationId=" + replyMessage.getJMSCorrelationID());
}
else
{
System.out.println("replyMessage is null");
}
ut.commit();
if (replyMessage instanceof TextMessage)
{
String replyString = ((TextMessage) replyMessage).getText();
System.out.println("REPLY MESSAGE TEXT=" + replyString);
String replyCID = replyMessage.getJMSCorrelationID();
System.out.println("REPLY MESSAGE CORRELID=" + replyCID);
}
}
|
When the "replyMessage = qReceiver.receive(timeout);" is called, I am seeing a connection on the MQ Queue via MQ Explorer "Open Input Count". So it appears it is making a connection to the MQ queue. (In my test environment, I have everything but my EJB turned off, so nothing else is connected to my queues.
So far no luck. In my EJB deployment descriptor, I think I have it set up correctly (I've tried different values, "Consumes", "Produces" "ConsumesProduces" but that did not seem to do the trick either).
Code: |
<message-destination-ref id="MessageDestinationRef_1248385705011">
<description>
the Queue that handles the requests</description>
<message-destination-ref-name>jms/JMSRewardsRequestQueueAlias</message-destination-ref-name>
<message-destination-type>javax.jms.Queue</message-destination-type>
<message-destination-usage>Produces</message-destination-usage>
<message-destination-link>JMSRewardsRequestQueue</message-destination-link>
</message-destination-ref>
<message-destination-ref id="MessageDestinationRef_1248463546859">
<description>
JMS queue where reply messages will be consumed.</description>
<message-destination-ref-name>jms/JMSRewardsReplyQueueAlias</message-destination-ref-name>
<message-destination-type>javax.jms.Queue</message-destination-type>
<message-destination-usage>Consumes</message-destination-usage>
<message-destination-link>JMSRewardsReplyQueue </message-destination-link>
</message-destination-ref>
|
|
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jul 28, 2009 11:20 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
you need to call start() on the receiver. |
|
Back to top |
|
 |
ndengland |
Posted: Tue Jul 28, 2009 12:14 pm Post subject: |
|
|
Newbie
Joined: 28 Jul 2009 Posts: 6
|
OK, I'm a bit confused.
I'm using javax.jms.MessageConsumer, which I can find no start() method for it.
Is there another API I should be using? |
|
Back to top |
|
 |
anilit99 |
Posted: Tue Jul 28, 2009 12:49 pm Post subject: |
|
|
 Voyager
Joined: 28 May 2009 Posts: 75 Location: London, UK
|
I think he mean the start method on the Connection object. In your case may be QueueConnection. _________________ "I almost care !" |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jul 28, 2009 12:51 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Sorry.
It's start() on the connection, not the receiver.
Look at the JMSConsumer sample that comes with MQ. |
|
Back to top |
|
 |
ndengland |
Posted: Tue Jul 28, 2009 1:21 pm Post subject: |
|
|
Newbie
Joined: 28 Jul 2009 Posts: 6
|
Oh thank you SO much!!! That looks like it did the trick, my EJB successfully read a message off of the queue.
Thanks a ton for the help. My next step is to do a selective get from the queue to get the right JMSCorrelId. I'll see if I can figure that out next. |
|
Back to top |
|
 |
ndengland |
Posted: Wed Jul 29, 2009 7:13 am Post subject: |
|
|
Newbie
Joined: 28 Jul 2009 Posts: 6
|
Thanks for all the help, I was able to send a request from JMS client to non-JMS and receive the reply based on the correlid.
Just missing that one line of code! |
|
Back to top |
|
 |
Vishnu Vardhan |
Posted: Mon Aug 03, 2009 12:39 am Post subject: unable to receive reply message from non-JMS producer |
|
|
Newbie
Joined: 31 Jul 2009 Posts: 2
|
Hi,
I'm also facing the same issue.
My application is running in WAS6.1 and uses Websphere MQ.
I could send the message. This sent msg is successfully processed by the other application(non-Java) and it also replies to this message. We could see the messages sitting in the queue. But the following code could not receive that reply message.
Can any one say, Is there any problem with the code?
Code: |
String message = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue replyQueue = null;
queueConnectionFactory = (QueueConnectionFactory) //JNDI look up
replyQueue = (Queue) //JNDI look up
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
String filter = "JMSCorrelationID = '" + correlationId + "'";
//correlationId = msgId of the sent message
QueueReceiver queueReceiver = queueSession.createReceiver(replyQueue, filter);
queueConnection.start();
TextMessage replyMessage = (TextMessage) queueReceiver.receive(queueReadTimeout);
message = replyMessage.getText();
if (queueConnection != null) {
queueConnection.close();
} |
Thanks in advance |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Mon Aug 03, 2009 12:44 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
Exactly what is your filter variable (correlationId) set to? Please provide an example.
Is the other application correctly setting the correlid field? How do you know this? |
|
Back to top |
|
 |
anilit99 |
Posted: Mon Aug 03, 2009 1:20 am Post subject: |
|
|
 Voyager
Joined: 28 May 2009 Posts: 75 Location: London, UK
|
may be you could remove the filter and test it, just to make sure you dont have a problem with the filter. _________________ "I almost care !" |
|
Back to top |
|
 |
Vishnu Vardhan |
Posted: Mon Aug 03, 2009 1:49 am Post subject: |
|
|
Newbie
Joined: 31 Jul 2009 Posts: 2
|
this is the messageId what I'm getting after sending the message.
"ID:414d51205753393544453034202020204a50af552033491e"
same thing I'm using as a correlation Id.
correlationId = "ID:414d51205753393544453034202020204a50af552033491e";
I do not know, what other application does(whether it is setting the correlation Id or not) and it cannot be known, because it is out of scope to me.
Anyway,
I will check by removing the filter condition and I'll get back to you.
Thanks for your comments.. |
|
Back to top |
|
 |
WMBDEV1 |
Posted: Mon Aug 03, 2009 2:03 am Post subject: |
|
|
Sentinel
Joined: 05 Mar 2009 Posts: 888 Location: UK
|
Vishnu Vardhan wrote: |
I do not know, what other application does(whether it is setting the correlation Id or not) and it cannot be known, because it is out of scope to me.
|
The reply message that it sends that lands on your queue is out of scope?
I wanted you to check that the correlid is correctly set on the message on your queue. This should be doable. |
|
Back to top |
|
 |
ndengland |
Posted: Mon Aug 03, 2009 6:35 am Post subject: |
|
|
Newbie
Joined: 28 Jul 2009 Posts: 6
|
Also, to get it to work correctly I had to make sure, in the WAS admin console on the queue destination settings: my "target client" for my reply queue had to be set to "JMS" when it's coming from a traditional MQ client. |
|
Back to top |
|
 |
|