0 Replies Latest reply on Jul 30, 2008 9:18 AM by Hans-Michael Rupp

    MDB sending messages

    Hans-Michael Rupp Novice

      Hallo I am experimenting with a MDB which should also be able to send back a message.

      On JBoss 4.2.2.GA out of the box.

      package mdbean;
      
      import javax.annotation.PostConstruct;
      import javax.annotation.PreDestroy;
      import javax.annotation.Resource;
      import javax.ejb.ActivationConfigProperty;
      import javax.ejb.MessageDriven;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.Session;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      import org.apache.log4j.Logger;
      import org.jboss.remoting.transport.coyote.ResponseMap;
      
      @MessageDriven(activationConfig = {
       @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
       @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/BafoegQueue"),
       @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
      public class JobControllerMDB implements MessageListener {
      
       private Logger log;
       @Resource(mappedName="QueueConnectionFactory")
       private QueueConnectionFactory queueConnectionFactory;
       private QueueConnection queueConnection;
       private QueueSession queueSession;
       @Resource(mappedName="BafoegRepsonseQueue")
       private Queue responseQueue;
      
       @PostConstruct
       public void init() {
       this.log = Logger.getLogger(this.getClass());
       try {
       this.queueConnection = queueConnectionFactory
       .createQueueConnection();
       this.queueSession = queueConnection.createQueueSession(false,
       Session.AUTO_ACKNOWLEDGE);
       queueConnection.start();
      
      
       } catch (JMSException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
       }
      
       public void onMessage(Message message) {
       log.info("Server onMessage");
       if (message instanceof TextMessage) {
       TextMessage textMessage = (TextMessage) message;
       try {
       log.info(textMessage.getText());
       QueueSender queueSender = queueSession.createSender(responseQueue);
       TextMessage responseTextMessage = this.queueSession.createTextMessage("foobar");
       queueSender.send(responseTextMessage);
       } catch (JMSException e) {
       log.error(e);
       }
       }
      
       }
      
       @PreDestroy
       public void destroy() {
      
       }
      
      }
      


      When this MDB receives a message following exception is thrown
      2008-07-30 15:06:15,524 DEBUG [org.jboss.ejb3.InitialContextFactory] Unable to access HA JNDI: javax.management.InstanceNotFoundException: jboss:service=HAJNDI is not registered.
      2008-07-30 15:06:15,524 ERROR [org.jboss.resource.adapter.jms.inflow.JmsServerSession] Unexpected error delivering message SpyTextMessage {
      Header {
       jmsDestination : QUEUE.BafoegQueue
       jmsDeliveryMode : 2
       jmsExpiration : 0
       jmsPriority : 4
       jmsMessageID : ID:32-12174231755081
       jmsTimeStamp : 1217423175508
       jmsCorrelationID: null
       jmsReplyTo : null
       jmsType : null
       jmsRedelivered : true
       jmsProperties : {JMS_JBOSS_REDELIVERY_COUNT=5}
       jmsPropReadWrite: false
       msgReadOnly : true
       producerClientId: ID:32
      }
      Body {
       text :blubber
      }
      }
      java.lang.NullPointerException
       at org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:49)
       at org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:87)
       at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:112)
       at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:107)
       at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:65)
       at org.jboss.ejb3.AbstractPool.create(AbstractPool.java:111)
       at org.jboss.ejb3.StrictMaxPool.get(StrictMaxPool.java:141)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:249)
       at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
       at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
       at $Proxy110.onMessage(Unknown Source)
       at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
       at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:891)
       at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
       at org.jboss.mq.SpySession.run(SpySession.java:323)
       at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:237)
       at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
       at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
       at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:756)
       at java.lang.Thread.run(Thread.java:595)
      2008-07-30 15:06:15,540 WARN [org.jboss.resource.adapter.jms.inflow.dlq.AbstractDLQHandler] Message redelivered=6 max=5 sending it to the dlq SpyTextMessage {
      Header {
       jmsDestination : QUEUE.BafoegQueue
       jmsDeliveryMode : 2
       jmsExpiration : 0
       jmsPriority : 4
       jmsMessageID : ID:32-12174231755081
       jmsTimeStamp : 1217423175508
       jmsCorrelationID: null
       jmsReplyTo : null
       jmsType : null
       jmsRedelivered : true
       jmsProperties : {JMS_JBOSS_REDELIVERY_COUNT=6}
       jmsPropReadWrite: false
       msgReadOnly : true
       producerClientId: ID:32
      }
      Body {
       text :blubber
      }
      }
      2008-07-30 15:06:15,977 DEBUG [org.jboss.mq.il.uil2.ServerSocketManagerHandler] Exiting on IOE
      java.net.SocketException: Connection reset
       at java.net.SocketInputStream.read(SocketInputStream.java:168)
       at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
       at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
       at org.jboss.util.stream.NotifyingBufferedInputStream.read(NotifyingBufferedInputStream.java:79)
       at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2196)
       at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(ObjectInputStream.java:2376)
       at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStream.java:2443)
       at java.io.ObjectInputStream$BlockDataInputStream.read(ObjectInputStream.java:2515)
       at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputStream.java:2664)
       at java.io.ObjectInputStream.readByte(ObjectInputStream.java:875)
       at org.jboss.mq.il.uil2.SocketManager$ReadTask.run(SocketManager.java:340)
       at java.lang.Thread.run(Thread.java:595)
      

      I had also tried looking up the QueueConnectionFactory and the queue.
      For the queue I had received a NameNotFoundException. Although the queue is clearly bound.
      +- queue (class: org.jnp.interfaces.NamingContext)
       | +- D (class: org.jboss.mq.SpyQueue)
       .....
       | +- BafoegQueue (class: org.jboss.mq.SpyQueue)
       | +- BafoegRepsonseQueue (class: org.jboss.mq.SpyQueue)
      

      I have both tried "queue/BafoegRepsonseQueue"
      and "BafoegRepsonseQueue".

      Can anybody help me with this?

      Thanks,

      Hans