2 Replies Latest reply on Jul 18, 2011 4:13 AM by michael.stoeckler

    JMS in AS7

    gmiller

      This used to work in AS6  -- I have tried to modify things to work in AS7, but can't quite get it working.  I am not getting any exceptions, but the messages are not being sent or maybe they are and not being delivered to the message bean.

      Any Ideas of what to try next?

       

      I am using AS7 running:

      ./standalone.sh --server-config=standalone-preview.xml

       

       

      standalone-preview.xml  -- parts

       

                  <jms-destinations>

                      <jms-queue name="stock_market_service_tick_queue">

                          <entry name="queue/stock_market_service_tick_queue"/>

                      </jms-queue>

                  </jms-destinations>

       

       

      package com.skyviewsoftware.stockmarket.test;

       

      import com.skyviewsoftware.stockmarket.TickPB;

      import java.util.Calendar;

      import java.util.logging.Level;

      import java.util.logging.Logger;

      import javax.annotation.ManagedBean;

      import javax.annotation.Resource;

      import javax.jms.Connection;

      import javax.jms.ConnectionFactory;

      import javax.jms.JMSException;

      import javax.jms.MessageProducer;

      import javax.jms.ObjectMessage;

      import javax.jms.Queue;

      import javax.jms.Session;

      import javax.ws.rs.POST;

      import javax.ws.rs.Path;

       

      @ManagedBean

      @Path("stockmarket/test")

      public class TestRWS

      {

          @POST

          @Path("sendtickmessage")

          public void sendTickMessage()

          {

              Connection theConnection = null;

              Session theSession = null;

              MessageProducer theProducer = null;

              try

              {

                  theConnection = connectionFactory.createConnection();

                  theSession = theConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                  theProducer = theSession.createProducer(tickQueue);

                  ObjectMessage theMessage = theSession.createObjectMessage();

                  TickPB theTick = new TickPB(null, Calendar.getInstance(), null, 0L);

                  theMessage.setObject(theTick);

                  theProducer.send(theMessage);

              }

              catch (Exception inException)

              {

                  logger.log(Level.SEVERE, inException.getMessage(), inException);

              }

              finally

              {

                  try

                  {

                      if (theProducer != null)

                      {

                          theProducer.close();

                      }

                      if (theSession != null)

                      {

                          theSession.close();

                      }

                      if (theConnection != null)

                      {

                          theConnection.close();

                      }

                  }

                  catch (JMSException inException)

                  {

                      logger.log(Level.SEVERE, inException.getMessage(), inException);

                  }

              }

          }

         

          private static final Logger logger = Logger.getLogger(TestRWS.class.getName());

         

          @Resource(name = "RemoteConnectionFactory", mappedName = "java:/RemoteConnectionFactory")

          private ConnectionFactory connectionFactory;

         

          @Resource(name = "stock_market_service_tick_queue", mappedName = "java:/queue/stock_market_service_tick_queue")

          private Queue tickQueue;

      }

       

      import com.skyviewsoftware.stockmarket.TickPB;

      import java.util.logging.Level;

      import java.util.logging.Logger;

      import javax.ejb.ActivationConfigProperty;

      import javax.ejb.MessageDriven;

      import javax.jms.JMSException;

      import javax.jms.Message;

      import javax.jms.MessageListener;

      import javax.jms.ObjectMessage;

       

      @MessageDriven(name="TickMB", activationConfig =

      {

          @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "AUTO_ACKNOWLEDGE"),

          @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

          @ActivationConfigProperty(propertyName = "destination", propertyValue="queue/stock_market_service_tick_queue")

      })

      public class TickMB implements MessageListener

      {

          public TickMB()

          {

          }

         

          @Override

          public void onMessage(Message inMessage)

          {

              try

              {

                  TickPB theTick = (TickPB) ((ObjectMessage) inMessage).getObject();

              }

              catch (JMSException inException)

              {

                  logger.log(Level.SEVERE, inException.getMessage(), inException);

              }

          }

       

         private static final Logger logger = Logger.getLogger(TickMB.class.getName());

      }

        • 1. Re: JMS in AS7
          gonne

          As I know message driven beans with JMS do not yet work with JBoss 7, it will be supported in JBoss 7.1. So you should wait for a nightly build that supports MDB with JMS or build a workaround with a singleton stateful bean as message listener.

          • 2. Re: JMS in AS7
            michael.stoeckler

            Hello Glen,

             

            you may also consider to take a look at the Seam 3 Framework. The JMS module provides a nice way to bridge between JMS-Messages and CDI-Events. But keep in mind, that currently not all is finished (Currently its 3.0.0.CR1), e.g. ... :

             

            "The default location of ConnectionFactory URL or JNDI name Seam JMS uses; it is hardcoded asConnectionFactory. That being said, if you're testing with Glassfish V3 you should define aConnectionFactory by that name as follows. Thanks Dan Allen for this tip:"

             

            You can spend some hours on this if you have to find it out the hard way ;-)