I successfully managed to send the message to queue name ReceiverQueue
on my localhost Jboss server, how can I retrieve message I sent to it or how do I check if there is any messages in the queue if any retrieve them. or can I get an explanation of some sort what is the best way to do this. Thank you
A working send/receive tutorial would be accept as well. Anything that will get me to just send to the queue and receive message from that queue will get accepted answer.
I'm using Spring.
I want a solution that does it using application context with bean injection ..
Here's an example showing how to set up a message-driven POJO in Spring. I'd recommend following this idiom if you're already using Spring.
As for the part about seeing how many messages are on the queue, I'd say you should be using the admin console for JBOSS, not your code.
I would recommend also using a tool like HermesJMS (http://www.hermesjms.com/confluence/display/HJMS/Home) to inspect the queue manager and queues. It's a great debugging tool.
Other than having a MessageDrivenBean listening to that queue?
EDIT: You are using spring just to create the payload, right? JMS is a JavaEE spec. You don't need to use Spring for actually sending/receiving messages. You don't have to manually check whether there are messages in the queue etc., either. All you need to do is have an MDB(MessageDrivenBean) set up like this,
}
And then send some JMS messages.
The queue is configured by the annotation. When a message is sent, JBoss will automatically trigger the MDB.
Standard JMS API steps:
1. Create a javax.naming.Context with the access details of the server
2. Look up javax.jms.QueueConnectionFactory in the context. Factory name is specific to the JMS server
3. Create a javax.jms.QueueConnection
4. Create a javax.jms.QueueSession
5. Look up your javax.jms.Queue in the context
Till now it is the same as sending....
6. Create a javax.jms.QueueReceiver with the session
7. JMS API provides 2 ways to retrieve a message:
7.a Wait for a message with one of the
receiver.receive()
methods7.b Implement javax.jms.MessageListener in your class and register it as the listener
JMS API will call your
onMessage()
method whenever a new message arrives8. Don't forget to start the listener:
9. Close the context (very important, when you access multiple JMS servers from the same program):
The above is a typical solution from a stand-alone application. In EJB environment you should use message driven beans. You can find ino on them on http://java.sun.com/javaee/6/docs/tutorial/doc/gipko.html and a tutorial on http://schuchert.wikispaces.com/EJB3+Tutorial+5+-+Message+Driven+Beans
Here is the working example you've asked for: