4 Replies Latest reply on Mar 17, 2011 7:32 PM by Nedland Rome

    ActivationConfigProperty Conflict

    Nedland Rome Newbie

      Hi guys,

       

      I have a problem with ActivationConfigProperty. The producer sends the message to the queue but the queue does not store it. I receive a message that the message has been sent on the jboss console output, but when I try to receive the message it gives a nullpointer exception.

       

      However when I remove the ActivationConfigProperty (the mandatory "destination" property required by jboss) I obviously get an error. Am I doing something wrong here? Without the activation config the queue count increases as I send messages, however with the annotation it simply doesn't increment and remains 0, so that pretty much proves that the messages are not being stored in the queue.

       

      Btw I'm using Jboss 6, so the ResourceAdapter shouldn't be required. Thanks in advance!

        • 1. ActivationConfigProperty Conflict
          Andy Taylor Master

          I would start by running one of the Javaee examples shipped with HornetQ and make sure they work. Also you havent reallygiven us enough info to give youanymore help, stacktrace, versions etc.

          • 2. Re: ActivationConfigProperty Conflict
            Nedland Rome Newbie

            Thanks for the reply Andy. Here is the Deployment Error shown in the jboss console if I remove Activation Config.

             

            DEPLOYMENTS IN ERROR:
              Deployment "jboss.j2ee:ear=cisEAR.ear,jar=test.jar,name=TestMessage,se
            rvice=EJB3" is in error due to the following reason(s): org.jboss.deployers.spi.Deplo
            ymentException: Required config property RequiredConfigPropertyMetaData@6608ed62[name
            =destination descriptions=[DescriptionMetaData@9d64598[language=en]]] for messagingTy
            pe 'javax.jms.MessageListener' not found in activation config [] ra=jboss.jca:service
            =RARDeployment,name='jms-ra.rar'
            
            
                    at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(Deployer
            sImpl.java:1228) [:2.2.0.GA]
                    at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeploy
            erImpl.java:905) [:2.2.0.GA]
                    at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.checkC
            omplete(MainDeployerPlugin.java:87) [:6.0.0.Final]
                    at org.jboss.profileservice.deployment.ProfileDeployerPluginRegistry.checkAll
            Complete(ProfileDeployerPluginRegistry.java:107) [:0.2.2]
                    at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootst
            rap.start(BasicProfileServiceBootstrap.java:135) [:6.0.0.Final]
                    at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootst
            rap.start(BasicProfileServiceBootstrap.java:56) [:6.0.0.Final]
                    at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(Abstra
            ctServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]
                    at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(Ab
            stractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]
                    at java.lang.Thread.run(Unknown Source) [:1.6.0_23]
            
            

             

            However for my testing I did include the ActivationConfigProperty to prevent the error above from showing up.

            Here is myMDB code:

             

            import javax.ejb.ActivationConfigProperty;
            import javax.ejb.MessageDriven;
            import javax.jms.Message;
            import javax.jms.MessageListener;
            
            @MessageDriven(
                                activationConfig = {
                                        @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
                                        @ActivationConfigProperty(propertyName="destination", propertyValue="queue/Test"),
                                })
            public class TestMessage implements MessageListener {
            
            
                public void onMessage(Message message) {
                          System.out.println("sent message");
                }
            }
            

             

            Here is the client code:

             

             

            import java.util.Properties;
            
            
            import javax.jms.Connection;
            import javax.jms.ConnectionFactory;
            import javax.jms.MessageConsumer;
            import javax.jms.MessageProducer;
            import javax.jms.Queue;
            import javax.jms.QueueConnection;
            import javax.jms.Session;
            import javax.jms.TextMessage;
            import javax.naming.Context;
            import javax.naming.InitialContext;
            
            
            public class TestMessageClient {
                      final static String queueName = "queue/Test";
            
                      /*****************************************************************************************************
                       * PRIMARY LOGIC METHODS
                       ******************************************************************************************************/
                      // This is a method used for obtaining the initial context and setting its
                      // properties
                      private static InitialContext getInitialContext()throws javax.naming.NamingException {
                                Properties p = new Properties();
                                p.put(Context.INITIAL_CONTEXT_FACTORY,
                                                    "org.jnp.interfaces.NamingContextFactory");
                                p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                                p.put(Context.PROVIDER_URL, "jnp://[ipaddress here]:1100");
            
            
                                return new InitialContext(p);
                      }
            
                      public static void main(String[] args) throws Exception {
                                processMessage(queueName);
                      }
            
                      private static void processMessage(String queueBinding) throws Exception {
                                QueueConnection cnn = null;
                                Connection connection = null;
                                InitialContext initialContext = null;
                                try {
                                          // Step 1. Create an initial context to perform the JNDI lookup.
                                          initialContext = getInitialContext();
            
                                          // Step 2. Perfom a lookup on the queue
                                          Queue queue = (Queue) initialContext.lookup(queueName);
            
                                          // Step 3. Perform a lookup on the Connection Factory
                                          ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
            
                                          // Step 4.Create a JMS Connection
                                          connection = cf.createConnection();
            
                                          // Step 5. Create a JMS Session
                                          Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            
                                          // Step 6. Create a JMS Message Producer
                                          MessageProducer producer = session.createProducer(queue);
            
                                          // Step 7. Create a Text Message
                                          TextMessage message = session.createTextMessage("This is a text message");
            
                                          System.out.println("Sent message: " + message.getText());
            
                                          // Step 8. Send the Message
                                          producer.send(message);
            
                                          // Step 9. Create a JMS Message Consumer
                                          MessageConsumer messageConsumer = session.createConsumer(queue);
            
                                          // Step 10. Start the Connection
                                          connection.start();
            
                                          // Step 11. Receive the message
                                          TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
                                          System.out.println("Received message: " + messageReceived.getText());
                                } finally {
                                          // cleanup
                                          if (cnn != null) {
                                                    cnn.close();
                                          }
                                }
                      }
            }
            

             

            As you can see this is taken directly from the example directory for testing. It gives me this NPE, @ the message receive line:

             

            Sent message: This is a text message
            Exception in thread "main" java.lang.NullPointerException
                      at unisys.test.message.TestMessageClient.processMessage(TestMessageClient.java:94)
                      at unisys.test.message.TestMessageClient.main(TestMessageClient.java:42)
            
            

             

            It seems that no message is being received, as when I print the TextMessage object it prints null. But jboss acknowledges the message:

             

            21:09:32,677 INFO  [STDOUT] sent message
            

             

            The odd thing is, the code works once I remove the @ActivationConfigProperty annotation below:

             

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

             

            It works fine. The messages are received and the NPE no longer appears. I'm using the version of hornetQ that come with Jboss 6.0.0.Final

             

            I can't remove that annotation since it's mandatory for Jboss MDB, and looking at the documentation these should be the minimum requirements for Jboss 6, i.e. there's no need for annotating ResourceAdapter or changes to any jboss configs. Correct me if I'm wrong.

             

            I'm guessing there's some config that I haven't setup that allows hornetQ to see the destination property used by jboss. I'm a little lost.

             

            Thanks for the help!

            • 3. Re: ActivationConfigProperty Conflict
              Andy Taylor Master

              yes, you need to have that preperty. I would start by running one of the many MDB examples shipped with HorfnetQ and go from there, they have all been tested and work.

              • 4. Re: ActivationConfigProperty Conflict
                Nedland Rome Newbie

                I found my solution! It was a newbie problem.

                 

                So although all my code was right and everything. The problem was with the concept of Messaging that caused the issue.

                 

                If you noticed I had an MDB and a separate client code that consumes the messages. With the JBoss annotation present the MDB gets deployed correctly, thus it consumes the messages leaving the queue empty. This means that whenever I call on the receive method it's actually obtaining nothing, thus throwing the NPE.

                 

                So once I removed the annotation, JBoss throws that error because I had an MDB in my project and it wasn't deployed because of that missing mandatory annotation. Without the MDB, nothing is consuming the messages in the queue thus whenever I invoke my receive method it works since the MDB is not deployed and not consuming the messages.

                 

                So in conclusion I either need to use an MDB or a remote client consumer to manually consume the messages. Depending on the requirements of the application.

                 

                I'm very new to JMS and overlooked this high level concept of messaging, so it's bound to occur sooner or later. Thanks for all the help and it's amazing what a good relaxed sleep can do. ^^