1 Reply Latest reply on Feb 3, 2012 5:10 AM by Ales Justin

    HornetQ CDI producing (and disposing) pattern fails with Connection is not associated with a managed connection

    Aleš Bregar Newbie

      Hi,

       

      I am playing around with JMS and let's assume that I am able to use MDB and some topic old way, without CDI. I came across the pattern (http://agoncal.wordpress.com/2011/09/25/injection-with-cdi-part-iii/) specially last part on producing and disposing.

      I did the same on top of as7.1 (nightly build 509) with the bellow code fragments:

       

      from Resource.class

           @Resource(mappedName = "java:/JmsXA")
          public static TopicConnectionFactory tcf;
          
          @Produces
          @Order
          @Resource(mappedName = "java:/topic/msdpHa")
          public static  Topic orderTopic;
      
          @Produces
          @Order
          public TopicConnection createTopicConnection() throws JMSException {
              return tcf.createTopicConnection();
          }
      
          @Produces
          @Order
          public TopicSession createTopicSession(@Order TopicConnection conn) throws JMSException {
              return conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
          }
      
          public void closeTopicConnection(@Disposes @Order TopicConnection conn) throws JMSException {
              conn.close();
          }
      
          public void closeTopicSession(@Disposes @Order TopicSession session) throws JMSException {
              session.close();
          }
      

       

      from publishing client:

       

           @Inject
          @Order
          private TopicSession tsession;
      
          @Inject
          @Order
          private Topic orderQueue;
      
      private void init(String text) throws Exception {
              tpublisher = tsession.createPublisher(orderQueue);
              msg = tsession.createTextMessage();
          }
      

       

       

      Running above code fails with:

       

      00:16:28,341 ERROR [stderr] (http--127.0.0.1-8080-1) javax.jms.IllegalStateException: Connection is not associated with a managed connection. org.hornetq.ra.HornetQRASession@79ea9e
      
      00:16:28,351 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.hornetq.ra.HornetQRASession.lock(HornetQRASession.java:139)
      00:16:28,351 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.hornetq.ra.HornetQRASession.createPublisher(HornetQRASession.java:686)
      00:16:28,351 ERROR [stderr] (http--127.0.0.1-8080-1)    at com.acme.core.TopicSenderServlet.init(TopicSenderServlet.java:87)
      00:16:28,351 ERROR [stderr] (http--127.0.0.1-8080-1)    at com.acme.core.TopicSenderServlet.service(TopicSenderServlet.java:53)
      

       

       

      I can live without CDI, but this is so much cleaner usage pattern that I wonder if it should work?