9 Replies Latest reply on Jun 9, 2014 3:04 PM by genman

    Bug in JMSProducer? Settings retained in JMSContext if retained in ApplicationContext

    genman

      I'm not sure this is a spec thing, but in WildFly I observe the following:

       

      1. Obtain a JMSContext using @Inject into an @ApplicationScoped bean.

      2. Create a JMSProducer using JMSContext.createProducer()

      3. Set the scheduled delivery time of a message

      4. Send the message.

       

      For the second call to send the message, the scheduled delivery time is used once again, although in a totally different thread. Which is totally mysterious.

       

      The work around is something like this:

       

      @RequestScoped
      class JMSProducerProducer {
      
      
          @Inject
          JMSContext context;
      
          @Produces @RequestScoped JMSProducer getProducer() {
              JMSProducer producer = context.createProducer();
              producer.clearProperties();
              producer.setDeliveryDelay(0);
              producer.setTimeToLive(0);
              return producer;
          }
      
      }
      
      

      I'm guessing the code is wrong in that the create method. Perhaps it should simply create a new instance each time?

       

      public class HornetQJMSContext implements JMSContext
      {
         @Override
         public JMSProducer createProducer()
         {
            checkSession();
            try
            {
               return new HornetQJMSProducer(this, getInnerProducer());
            }
            catch (JMSException e)
            {
               throw JmsExceptionUtils.convertToRuntimeException(e);
            }
         }
      
         private synchronized MessageProducer getInnerProducer() throws JMSException
         {
            if (innerProducer == null)
            {
               innerProducer = session.createProducer(null);
            }
      
            return innerProducer;
         }
      
      

       

      For example:

       

      diff --git a/hornetq-jms-client/src/main/java/org/hornetq/jms/client/HornetQJMSContext.java b/hornetq-jms-client/src/main/java/org/hornetq/jms/client/HornetQJMSContext.java
      index 27b8e2d..f3c51c5 100644
      --- a/hornetq-jms-client/src/main/java/org/hornetq/jms/client/HornetQJMSContext.java
      +++ b/hornetq-jms-client/src/main/java/org/hornetq/jms/client/HornetQJMSContext.java
      @@ -58,7 +58,6 @@
          private final HornetQConnectionForContext connection;
          private Session session;
          private boolean autoStart = HornetQJMSContext.DEFAULT_AUTO_START;
      -   private MessageProducer innerProducer;
          private boolean xa;
          private boolean closed;
      
      @@ -112,7 +111,7 @@ public JMSProducer createProducer()
             checkSession();
             try
             {
      -         return new HornetQJMSProducer(this, getInnerProducer());
      +         return new HornetQJMSProducer(this, session.createProducer(null));
             }
             catch (JMSException e)
             {
      @@ -120,16 +119,6 @@ public JMSProducer createProducer()
             }
          }
      
      -   private synchronized MessageProducer getInnerProducer() throws JMSException
      -   {
      -      if (innerProducer == null)
      -      {
      -         innerProducer = session.createProducer(null);
      -      }
      -
      -      return innerProducer;
      -   }
      -
          /**
           *
           */