[Messaging, JMS & JBossMQ] - Queue - I can send but cannot receive
by vitor_b
Hello
JBoss: 4.0.5 GA
I'm still facing some problems working with JMS.
The last problem is that i cannot receive message from queue. I can send it, but cannot receive it later. All from mothod inside simle stateless session bean. This method works in a transaction (Container, Required).
First getting stuff
InitialContext ictx = new InitialContext();
| ConnectionFactory cf = (ConnectionFactory) ictx.lookup("java:JmsXA");
| Connection con = cf.createConnection();
| Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
| Queue queue = (Queue ) ictx.lookup("queue/testQueue");
|
| logger.info(queue.getQueueName());
Now we can perform some operations on queue:
First we can send message:
MessageProducer sender = session.createProducer(queue);
|
| Order order = new Order();
| order.setOrderId("orderId");
|
| Message message = session.createObjectMessage(order);
|
| sender.send(message);
| logger.info("Message has been sent");
Sending messages works fine.
Now i would like to receive one message:
MessageConsumer consumer = session.createConsumer(queue);
| Message m = consumer.receiveNoWait();
|
| if (m == null){
| logger.error("m is null");
| }else{
| logger.info("got message, yupi");
| }
But I cannot get message from queue "testQueue". Everytime single time i get null. Queue depth is huge now after so many tries :(
I deployed MDB, and that MDB was able to consume messages from this queue. I have no idea what i'm doing wrong. Any sugestions?
Thank you for all your replies in advance.
vitor_b
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4031032#4031032
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4031032
19Â years, 1Â month
[Messaging, JMS & JBossMQ] - Re: import org.jboss.mq.server.jmx.Queue
by vitor_b
Hello
I have a solution for you. The key is JMX API.
As you know there is a MBean which you can view using jboss jmx console.
One thing we have to do is to acces that MBean. Here is some code i have written for you:
String domain = "jboss.mq.destination";
| String service = "service=Queue";
| String name = "name=testQueue";
|
| String stringObjectName = domain + ":" + service + "," + name;
|
| MBeanServer server = MBeanServerLocator.locateJBoss();
|
| try{
| ObjectName queueObjectName = ObjectName.getInstance(stringObjectName);
|
| org.jboss.mq.server.jmx.QueueMBean queueMBean =
| (org.jboss.mq.server.jmx.QueueMBean) MBeanServerInvocationHandler.newProxyInstance(
| server,
| queueObjectName,
| org.jboss.mq.server.jmx.QueueMBean.class,
| false
| );
|
| logger.info("queue depth: " + queueMBean.getQueueDepth());
|
| }catch (Exception e){
| logger.info("cannot get depth of the queue: " + e.getMessage(),e);
| }
When you have a proxy then you can get all queue properties by calling method: getNameOfAttribute (ex. queueMBean.getQueueDepth();)
These three strings set up at the begining are taken from jmx-console page for MBean monitoring Queue.
If you have any questions, just ask.
As a reward please look at my question (Queue - I can send but cannot receive) i'm going to write right now.
Since you are working with queues maybe you will be able to help me.
Take care
vitor_b
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4031029#4031029
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4031029
19Â years, 1Â month