3 Replies Latest reply on Dec 18, 2013 6:37 PM by rvcoutinho

    MDB in WildFly 8.0.0.Alpha4

    rvcoutinho

      Hi,

       

      I have been trying to make a simple MDB to work in WildFly 8.0.0.Alpha4 with no success so far.

       

      Looks like the queue has been correctly registered (during initialization), and the message is sent with no exceptions. But the message driven bean is never invoked.

       

      The Message Driven Bean is described below:

       

      @MessageDriven(name = "Queue/AppNotification/Send", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/Queue/AppNotification/Send"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
      @JMSDestinationDefinition(name = "java:/jms/Queue/AppNotification/Send", interfaceName = "javax.jms.Queue", destinationName = "AppNotificationSendQueue")
      public class AppNotificationSender implements MessageListener {
      
        @Override
        public void onMessage(final Message message) {
        // Tries to send the application notification.
        try {
        // Gets the original notification.
        AppNotification appNotification = message.getBody(AppNotification.class);
        ...
        }
        // If the JMS message cannot be processed.
        catch (JMSException exception) {
        ...
        }
        }
      }
      
      

       

      The message producer (apparently working) is defined as following:

       

      @Stateless(name = "Component/Message/AppNotification")
      public class AppNotificationComponent extends AbstractGenericComponent<AppNotification, Integer> {
      
      
        @Resource(mappedName = "java:/ConnectionFactory")
        private ConnectionFactory connectionFactory;
      
      
        @Resource(lookup = "java:/jms/Queue/AppNotification/Send")
        private Queue sendQueue;
      
      
        public void sendMessage(AppNotification notification) {
        // Asserts that the message is not null.
        PreConditions.assertParamNotNull(DAOParamKeys.ENTITY, notification);
        // Validates the current message (and throws an exception for the found violations).
        ValidationException.throwViolationExceptions(Validation.buildDefaultValidatorFactory().getValidator()
        .validate(notification));
        // Sends the notification to the queue. FIXME
        // jmsContext.createProducer().send(sendQueue, notification);
        Connection connection = null;
        try {
        // Creates the JMS connection.
        connection = connectionFactory.createConnection();
        // Starts a new JMS session.
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Creates a producer for the send queue.
        MessageProducer messageProducer = session.createProducer(sendQueue);
        // Starts the JMS connection.
        connection.start();
        // Creates a new message with the notification.
        ObjectMessage notificationMsg = session.createObjectMessage(notification);
        // Sends the message.
        messageProducer.send(notificationMsg);
        }
        // If message cannot be sent.
        catch (JMSException exception) {
        // FIXME
        exception.getCause();
        }
        // At the end.
        finally {
        try {
        // Closes the JMS connection.
        connection.close();
        }
        // If message cannot be sent.
        catch (JMSException exception) {
        // FIXME
        exception.getCause();
        }
        }
      
      
        }
      }
      
      

       

       

      Any ideas on what I am doing wrong?

       

      Thanks in advance,

       

      Rômulo Coutinho.

        • 1. Re: MDB in WildFly 8.0.0.Alpha4
          wdfink

          Did you use two different deployments?

          Did you see that any errors/warn in the logfile?

          You might read the message direct from the same method to see whether you can read it manually.

          Also you might use quickstart/helloworld-jms to verify your app.

          • 2. Re: MDB in WildFly 8.0.0.Alpha4
            rvcoutinho

            Hi,

             

            No errors/warnings in the log.

             

            The classes are in two different JARs within the same EAR.

             

            I also read the quickstart/helloworld-jms. As described above, I first used the jmsContext solution (part of the JavaEE 7 spec). Then, I switched to the same solution as in the article. No luck though.

             

            I will try to run the example in the article in a plain project.

             

            Thanks again,

             

            Rômulo Coutinho.

            • 3. Re: Re: MDB in WildFly 8.0.0.Alpha4
              rvcoutinho

              Hi,

               

              Finally, got it to work. The problem was with the activation property:

               

              1.   @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/Queue/AppNotification/Send") // Wrong 
              2.   @ActivationConfigProperty(propertyName = "destination", propertyValue = "/jms/Queue/AppNotification/Send") // Right

               

              Found it out thanks to the helloworld-mdb.

               

              Thanks again.