0 Replies Latest reply on May 6, 2015 7:05 AM by Manuel Franqueira

    mdb activemq consumer

    Manuel Franqueira Newbie

      I'm using JBoss7.1 and I have to consume messages from an ativemq server.

       

      I developed a consumer that works (when I run it...), but I want to construct an MDB that is always listen queue arrival.

      The consumer I have is this:

       

      public void messageConsumer() throws Exception {

          try {

          

                  // Create a ConnectionFactory

                  ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://srv-infinispan-pre:61616");

       

       

                  // Create a Connection

                  Connection connection = connectionFactory.createConnection();

                  connection.start();

       

       

                  // Create a Session

                  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

       

       

                  // Create the destination (Topic or Queue)

                  Destination destination = session.createQueue("demoQueue");

       

       

                  // Create a MessageConsumer from the Session to the Topic or Queue

                  MessageConsumer consumer = session.createConsumer(destination);

       

       

                  // Wait for a message

                  Message message = consumer.receive(1000);

       

       

                  if (message instanceof TextMessage) {

                      TextMessage textMessage = (TextMessage) message;

                      String text = textMessage.getText();

                      System.out.println("Received: " + text);

                  } else {

                      System.out.println("Received: " + message);

                  }

       

       

                  consumer.close();

                  session.close();

                  connection.close();

              } catch (Exception e) {

                  System.out.println("Caught: " + e);

                  e.printStackTrace();

              }

          }

       

      How can I have an MDB that is listen every message arrival and consume it?

      I tried do develop an MDB with this configuration, but this doesn't work.

       

      @MessageDriven(name = "HelloWorldQueueMDB", activationConfig = {

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

              @ActivationConfigProperty(propertyName = "destination", propertyValue = "demoQueue"),

              @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "tcp://srv-infinispan-pre:61616"),

      //        @ActivationConfigProperty(propertyName = "connectorClassName", propertyValue = "org.apache.activemq.jndi.ActiveMQInitialContextFactory"),

              @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })

       

       

      Thanks.