Hi,
I have an issue where I send a simple test text message to a queue. Then the MDB is
supposed to pick this message up and display the text. I can't see any issues with my
coding, and I have tested to ensure that the message does get stored in the queue, by
retrieving it straight after adding to the queue.
Here is the action handler sending the text to the queue.
| package com.distributed.action;
|
| import org.jbpm.graph.def.ActionHandler;
| import org.jbpm.graph.exe.ExecutionContext;
|
| import javax.jms.ConnectionFactory;
| import javax.jms.Connection;
| import javax.jms.MessageProducer;
| import javax.jms.Queue;
| import javax.jms.Session;
| import javax.jms.TextMessage;
| import javax.naming.InitialContext;
| /**
| import javax.jms.MessageConsumer;
| */
|
| public class SendMessageToQueueForPartTwo implements ActionHandler
| {
|
| private static final long serialVersionUID = 1L;
|
| InitialContext jndi = null;
| ConnectionFactory conFactory = null;
| Connection connection = null;
| Session session = null;
| MessageProducer producer = null;
| TextMessage textMessage = null;
| TextMessage receivedMessage = null;
|
| public void execute(ExecutionContext context) throws Exception
| {
| try
| {
| jndi = new InitialContext();
| System.out.println("SendMessageToQueueForPartTwo: jndi Initial Context
created");
|
| conFactory = (ConnectionFactory)jndi.lookup("ConnectionFactory");
| System.out.println("SendMessageToQueueForPartTwo: ConnectionFactory
created");
|
|
| connection = conFactory.createConnection();
| System.out.println("SendMessageToQueueForPartTwo: Connection created");
| session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
| System.out.println("SendMessageToQueueForPartTwo: Session created");
| Queue queue = (Queue) jndi.lookup("queue/jbpmQueue");
| System.out.println("SendMessageToQueueForPartTwo: Looked up jbpmQueue");
| if (queue == null)
| {
| System.out.println("SendMessageToQueueForPartTwo: Queue Not Found...Creating
Queue");
| queue = session.createQueue("queue/jbpmQueue");
| }
| producer = session.createProducer(queue);
| System.out.println("SendMessageToQueueForPartTwo: Producer Created");
|
| textMessage = session.createTextMessage("Hello, has this worked?");
| System.out.println("SendMessageToQueueForPartTwo: textMessage Created");
| producer.send(textMessage);
| System.out.println("SendMessageToQueueForPartTwo: textMessage sent to " +
queue.getQueueName() + " queue");
|
| /** The following code was to check that the message was passed to the Queue
| MessageConsumer consumer = session.createConsumer(queue);
| System.out.println("MessageConsumer created");
|
| connection.start();
| System.out.println("Connection started");
|
| receivedMessage = (TextMessage) consumer.receive();
| System.out.println("The Message "+ receivedMessage.getText());
| */
|
| }
| finally
| {
| if(jndi != null)
| {
| try
| {
| jndi.close();
| }
| catch(Exception e)
| {
| throw e;
| }
| }
| }
| }
| }
Here is the Message Driven Bean.
| package com.distributed.action;
|
| import javax.ejb.EJB;
| import javax.ejb.MessageDriven;
| import javax.ejb.ActivationConfigProperty;
| import javax.jms.JMSException;
| import javax.jms.Message;
| import javax.jms.MessageListener;
| import javax.jms.TextMessage;
|
| @MessageDriven(mappedName = "jms/PartTwoMDB", activationConfig =
| {
| @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue =
"Auto-acknowledge"),
| @ActivationConfigProperty(propertyName="destinationType",
propertyValue="javax.jms.Queue"),
| @ActivationConfigProperty(propertyName="destination",
propertyValue="/queue/jbpmQueue")
| })
|
| public class PartTwoMDB implements MessageListener
| {
| @EJB
| private static final long serialVersionUID = 1L;
|
| public void onMessage(Message inMessage)
| {
| TextMessage textMessage = null;
| try
| {
| if(inMessage instanceof TextMessage)
| {
| textMessage = (TextMessage) inMessage;
| System.out.println("PartTwoMDB: Message received: "+
textMessage.getText());
| }
| else
| {
| System.out.println("PartTwoMDB: MEssage of wrong type: " +
inMessage.getClass().getName());
| }
| }
| catch (JMSException e)
| {
| e.printStackTrace();
| }
| catch (Throwable t)
| {
| t.printStackTrace();
| }
|
| }
| }
|
I would expect it to print the message text message but nothing happens.
Would anyone be able to assist?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4133497#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...