Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Wait to Get a message from jms queue  RSS feed

 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am recieving messages from a jms queue. I want to wait for 2 seconds after every message. using method reciever.recieve( 2000 ) doesn't seem to work. how do i do this. This is the first time i m using jms.

Thanks
Imad
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of the method cannot be "recieve". If it's anything like that (I am not looking in the documentation) then it must be "receive". However it might help if you clarified what "doesn't seem to work" means. I am just guessing at possible compile-time errors.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait a minute, I just read your requirement more carefully: "I want to wait for 2 seconds after every message". This is not the same as waiting for up to 2 seconds to receive a message, which is what I originally assumed you meant. If you want to wait for 2 seconds thenwill do nothing for 2 seconds.
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sir

I am sorry i spelled receive wrong. This is what I am doing

I have a servlet and in its init method I have following code

init (){
......
receiver = this.session.createReceiver(endpointQ);
receiver.setMessageListener(this);
this.connect.start();
....
}
then i have my onMessage method in this same class.

Every thing is working fine but I want an upto two seconds delay with every message consumed.

I'll try your thread.sleep() method but I just want to avoid using threads. If you can think of something else please let me know. Really appreciate your reply.
Thanks
Imad
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually here is the detail. I am sending out calls. if the ports to send out calls are all busy then I want to stop receiving the message. and then once I have a free port I want to able to ask for a message again.

Hope someone can help me in this.
Thanks
Imad
 
Andreas Schaefer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you cannot use the MessageListener. You must start your own thread, wait to a port to become available and then receive a message from a Message Consumer. This way you control the timeing of the messaeg receiption and not the JMS server which controls the Message Listener.

-Andy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!