Class JMSOperation


  • @Technical
    @Bean
    @Singleton
    public class JMSOperation
    extends Object
    A JMS operation processor. But why?
    In fact, JMSContext can be used as application-managed way or it can be used as container-managed.

    In the first way and according to the documentation, the JMSContext must be get by using ConnectionFactory and it has to be explicitly closed when it is no more needed. For example:

       @Resource
       private javax.jms.ConnectionFactory jmsConnectionFactory;
    
       ...
    
       public void performSend(Destination destination , Serializable event)
         try (JMSContext context = jmsConnectionFactory.createContext()) {
           final JMSProducer producer = context.createProducer();
           producer.send(destination, event);
         }
       }
     

    So that is kind of manual management.

    In the second way, the JMSContext must be injected and used directly. For example:

       @Inject
       private javax.jms.JMSContext context;
    
       ...
    
       public void performSend(Destination destination , Serializable event)
         final JMSProducer producer = context.createProducer();
         producer.send(destination, event);
       }
     

    There is no manual management here concerning the JMSContext because that is handled by the container.
    But to be managed efficiently, a JTA transaction must exist, and also, the following rule must be verified (from documentation of JMSContext): Applications running in the Java EE web and EJB containers are not permitted to create more than one active session on a connection so combining them in a single object takes advantage of this restriction to offer a simpler API.

    So, to get the code the simplest possible in callers, this class provides static method that simplifies the processing of a JMS operation by observing the different mandatory rules concerning the JMSContext.

    Author:
    Yohann Chastagnier
    • Method Detail

      • realize

        public static void realize​(JMSOperation.Operation operation)
        Realizes a JMS operation with a managed JMSContext.
        Parameters:
        operation - the operation to realize.
        See Also:
        JMSOperation