5 Replies Latest reply on Apr 2, 2018 6:14 PM by dmarley

    Not able to send message to a Topic configured on WildFly 9.Need help

    chandrasachin16

      Hi All,

       

      I am trying to deploy message driven bean on WildFly 9.0.0 (wildfly-9.0.0.Final) which I am doing for the first time.My jar  contaning the MDB is getting deployed properly,but when I try to put a message through a java client it doesn't work.The exception which I get while running my client is as below-

       

      java.lang.UnsupportedOperationException: Cannot specify destination if producer has a default destination-

       

      My test Client java file is as below--

       

       

      public class TestClient {

       

      public final static String JNDI_FACTORY="org.jboss.naming.remote.client.InitialContextFactory";


        //*************** Using the RemoteConnectionFactory JNDI name *************************


        public final static String JMS_FACTORY="jms/RemoteConnectionFactory";

      //*************** Created Queue's JNDI name *************************

       

       

        private static TopicConnectionFactory tConFactory;

        private static TopicConnection tCon;

        private static TopicSession tSession;

       

       

        private static Topic topic;

       

        public static void main(String[] args) throws JMSException, NamingException {

       

       

        Context context=getInitialContext();

       

       

        tConFactory = (TopicConnectionFactory) context.lookup(JMS_FACTORY);

       

       

        //*************** Creating Queue Connection using the UserName & Password *************************

        tCon = tConFactory.createTopicConnection("sachin2","Mycomputer@1234");//<------------- Change the UserName & Password

       

       

        tSession = tCon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        topic = (Topic) context.lookup("jms/topic/test");

       

       

        TopicPublisher publisher=tSession.createPublisher(topic);

        System.out.println("before writing message...................");

        TextMessage msg=tSession.createTextMessage();

        msg.setText("Hello sachin........");

        System.out.println("After setting message...................");

        publisher.send(topic, msg);

        System.out.println("After sending...................");

        tCon.start();

       

       

       

       

        }

       

       

        private static Context getInitialContext() throws NamingException{

       

       

        Properties jndiProps = new Properties();

        jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");

        jndiProps.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");

        jndiProps.put(Context.SECURITY_PRINCIPAL, "sachin2");

        jndiProps.put(Context.SECURITY_CREDENTIALS, "Mycomputer@1234");

        jndiProps.put("jboss.naming.client.ejb.context", true);

        Context ctx = new InitialContext(jndiProps);

       

       

        return  ctx;

        }

       

       

      }

       

      ///////////////////////////////////////////////////////////////////////////////////////////////    Wild Fly Server logs//////////////////////////////////////////////////////////////////////////////////////////////////////////

       

      The similar thing was working on Jboss AS 7.

      If you see the logs below it shows the MDB is started(highlighted in bold)

       

      java:/ConnectionFactory

      2015-08-03 09:21:18,617 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 74) HQ221003: trying to deploy queue jms.queue.DLQ

      2015-08-03 09:21:18,631 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 76) WFLYMSG0002: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory

      2015-08-03 09:21:18,637 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 73) HQ221003: trying to deploy queue jms.topic.testTopic

      2015-08-03 09:21:18,638 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-2) WFLYJCA0007: Registered connection factory java:/JmsXA

      2015-08-03 09:21:18,645 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 75) HQ221003: trying to deploy queue jms.queue.ExpiryQueue

      2015-08-03 09:21:18,697 INFO  [org.hornetq.ra] (MSC service thread 1-2) HornetQ resource adaptor started

      2015-08-03 09:21:18,700 INFO  [org.jboss.as.connector.services.resourceadapters.ResourceAdapterActivatorService$ResourceAdapterActivator] (MSC service thread 1-2) IJ020002: Deployed: file://RaActivatorhornetq-ra

      2015-08-03 09:21:18,704 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-2) WFLYJCA0002: Bound JCA ConnectionFactory [java:/JmsXA]

      2015-08-03 09:21:18,704 INFO  [org.jboss.as.messaging] (MSC service thread 1-4) WFLYMSG0002: Bound messaging object to jndi name java:jboss/DefaultJMSConnectionFactory

      2015-08-03 09:21:19,350 INFO  [org.jboss.ws.common.management] (MSC service thread 1-3) JBWS022052: Starting JBoss Web Services - Stack CXF Server 5.0.0.Final

      2015-08-03 09:21:21,131 INFO  [org.jboss.as.ejb3] (MSC service thread 1-3) WFLYEJB0042: Started message driven bean 'AcccountMessageProcessor' with 'hornetq-ra.rar' resource adapter

      2015-08-03 09:21:21,260 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 45) WFLYSRV0010: Deployed "AccountEJB.jar" (runtime-name : "AccountEJB.jar")

       

      My standalone-full.xml jms configuration is below where I have configured my topic as below-

       

       

      <jms-destinations>

                          <jms-queue name="ExpiryQueue">

                              <entry name="java:/jms/queue/ExpiryQueue"/>

                          </jms-queue>

                          <jms-queue name="DLQ">

                              <entry name="java:/jms/queue/DLQ"/>

                          </jms-queue>

                          <jms-topic name="testTopic">

                              <entry name="java:jboss/exported/jms/topic/test"/>

                          </jms-topic>

             </jms-destinations>

       

       

      I am not sure why this is not happening though the entry of topic starts with java:jboss/exported

       

      Can anybody please guide me.

       

      Regards

      Sachin

        • 1. Re: Not able to send message to a Topic configured on WildFly 9.Need help
          mayerw01

          I guess this message is a bit confusing.

          But you should specify the destination either when creating the TopicPublisher or when sending the message. Not both.

          So you may change your send line to: publisher.send(msg);

          or your creation line to: TopicPublisher publisher = tSession.createPublisher(null);

          1 of 1 people found this helpful
          • 2. Re: Not able to send message to a Topic configured on WildFly 9.Need help
            chandrasachin16

            Hi ,

             

            Thanks a lot for replying.Your suggestion is correct and I was doing it the wrong way.Now it is working after changing it to below code as suggested by you.

            TopicPublisher publisher = tSession.createPublisher(null);


            Thanks,Thanks a lot for your help. Below is the complete code of the test client.


            But still my query remains. I cross checked with the old test client( i.e. without adding the TopicPublisher publisher = tSession.createPublisher(null)).I tried to send message to an MDB deployed on Jboss AS 7 and there it does not seem to cause any issues. So what has changed in Wildfly or is it that the way we were putting message on Jboss AS 7 was not correct which was rectified on Wildfly. I am very curious to know about.Also if I try to put message on JBoss As 7 using both the ways i.e ( by setting TopicPublisher publisher = tSession.createPublisher(null)  and also if I keep it as  TopicPublisher publisher = tSession.createPublisher(topic) ),both the ways work perfectly fine on AS 7. I would be eager to understand.

             

             

            //////////////////////////////////////////////////////////////    Test Client Modified Sample  Code    ///////////////////////////////////////////////////////////////////////////////////////

            public class TestClient {

             

              public final static String JNDI_FACTORY="org.jboss.naming.remote.client.InitialContextFactory";

              public final static String JMS_FACTORY="jms/RemoteConnectionFactory";

              private static TopicConnectionFactory topicConnFactory;

              private static TopicConnection topicConnnection;

              private static TopicSession topicSession;

              private static Topic topic;

             

             

              public static void main(String[] args) throws JMSException, NamingException {

             

             

              Context context=getInitialContext();

              topicConnFactory = (TopicConnectionFactory) context.lookup(JMS_FACTORY);

              topicConnnection = topicConnFactory.createTopicConnection("sachin2","Mycomputer@1234");

              topicSession = topicConnnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

              topic = (Topic) context.lookup("jms/topic/test");

              TopicPublisher publisher=topicSession.createPublisher(null);        //Setting it to null

              TextMessage msg=topicSession.createTextMessage();

              msg.setText("Hello");

              publisher.send(topic,msg);   

              topicConnnection.start();

              }

             

              private static Context getInitialContext() throws NamingException{

              Properties jndiProps = new Properties();

              jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");

              jndiProps.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");

              jndiProps.put(Context.SECURITY_PRINCIPAL, "sachin2");

              jndiProps.put(Context.SECURITY_CREDENTIALS, "Mycomputer@1234");

              jndiProps.put("jboss.naming.client.ejb.context", true);

              Context ctx = new InitialContext(jndiProps);

              return  ctx;

              }

             

            }

             

             

            Regards

            Sachin

            1 of 1 people found this helpful
            • 3. Re: Not able to send message to a Topic configured on WildFly 9.Need help
              mayerw01

              I don't think this is a bug but the specification changed.

              If you compare the API documentations you may realize that in JEE7 the UnsupportedOperationException had been added to the send methods of the MessageProducer interface.

              • 4. Re: Not able to send message to a Topic configured on WildFly 9.Need help
                chandrasachin16

                Ok. Got it. Once again thanks a lot.

                 

                 

                Regards

                Sachin

                • 5. Re: Not able to send message to a Topic configured on WildFly 9.Need help
                  dmarley

                  Helped me out.  Thanks.