Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

receiveNoWait() returns null when there are messages...

Status
Not open for further replies.

GhostDragon

Programmer
May 23, 2003
2
US
Using Java...

I have code that works from the commandline but when I use it within my actual application receiveNoWait() returns null. recieve() works fine but my app needs receiveNoWait() in order to proceed. I double-check that there are messages available. I am new to MQSeries so I may be overlooking something very simple.

tSess = tConn.createTopicSession( false, Session.AUTO_ACKNOWLEDGE );
t = (Topic)context.lookup( queueJNDI );
if( tSub==null )
tSub = tSess.createSubscriber(t);
..............

msg = (TextMessage)tSub.receiveNoWait(); //this blows up
 
You did not specify what does "this blows up" mean. Do you get an error return code. If it is 2033, it means that the messages are not yet available to be gotten. And since you specified nowait, it does not wait for the messages to be committed.

I am not sure of the definition of nowait function, but i would bet it would work if you first put messages to the queue using say amqsput and then run your java app. It may be that the messages were not committed when you ran your java app.



Cheers
KK
 
it just returns 'null' because it 'thinks' there are no messages. i have found that if i put a message in after my client has made a connection then all is well. if the messages are in there before that the client won't see them. i need to be able to occassionally connect, get messages, and go about my biz...

thank you for your reply!
 
Straight from the manuals...

receiveNoWait
public Message receiveNoWait() throws JMSException
Receive the next message if one is immediately available.
Returns:
the next message produced for this message consumer, or null if one is not available.
Throws:
JMSException - if JMS fails to receive the next message because of an error.

This would kind of indicate that receiveNoWait is meant to retrieve only those messages that have been put after you have started your app.

But in any case, if you post your code here, making it simple, i shall try it out when i have a chance.



Cheers
KK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top