Class RMQObjectFactory

  • All Implemented Interfaces:
    javax.naming.spi.ObjectFactory

    public class RMQObjectFactory
    extends java.lang.Object
    implements javax.naming.spi.ObjectFactory
    JNDI Factory to create resources in containers such as Tomcat.

    An example Tomcat configuration for a ConnectionFactory would look like:

     <Resource name="jms/ConnectionFactory" type="jakarta.jms.ConnectionFactory"
               factory="com.rabbitmq.jms.admin.RMQObjectFactory"
               username="guest"
               password="guest"
               virtualHost="/"
               host="localhost"/>
     

    Alternatively, a AMQP uri can be used:

     <Resource name="jms/ConnectionFactory" type="jakarta.jms.ConnectionFactory"
               factory="com.rabbitmq.jms.admin.RMQObjectFactory"
               uri="amqp://guest:guest@127.0.0.1"
     

    the type attribute can be ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory or the actual classname of the implementation, RMQConnectionFactory.

    A destination, Queue or Topic, can be created using the following configuration (Queue first):

     <Resource name="jms/Queue" type="jakarta.jms.Queue"
               factory="com.rabbitmq.jms.admin.RMQObjectFactory"
               destinationName="queueName"/>
     

    and a Topic would be created thus:

     <Resource name="jms/Topic" type="jakarta.jms.Topic"
               factory="com.rabbitmq.jms.admin.RMQObjectFactory"
               destinationName="topicName"/>
     

    An example Wildfly configuration for a ConnectionFactory would look like:

     <object-factory name="java:global/jms/ConnectionFactory" module="org.jboss.genericjms.provider" class="com.rabbitmq.jms.admin.RMQObjectFactory">
         <environment>
             <property name="className" value="jakarta.jms.ConnectionFactory"/>
             <property name="username" value="guest"/>
             <property name="password" value="guest"/>
             <property name="virtualHost" value="/"/>
             <property name="host" value="localhost"/>
         </environment>
     </object-factory>
     

    Valid types are:

     jakarta.jms.ConnectionFactory
     jakarta.jms.QueueConnectionFactory
     jakarta.jms.TopicConnectionFactory
     jakarta.jms.Topic
     jakarta.jms.Queue
     

    Valid properties for a ConnectionFactory are:

    • uri
    • host
    • password
    • port
    • queueBrowserReadMax
    • onMessageTimeoutMs
    • channelsQos
    • ssl
    • terminationTimeout
    • username
    • virtualHost
    • className - only applies when properties are provided via environment HashTable
    and are applied in this order, if they are present. If a property is not present, or is not set by means of the uri attribute, the default value is the same as that obtained by instantiating a RMQConnectionFactory object with the default constructor.

    Properties for a Topic or a Queue are:

    • destinationName
    TODO Implement socket options.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object createConnectionFactory​(javax.naming.Reference ref, java.util.Hashtable<?,​?> environment, javax.naming.Name name)
      Creates a RMQConnectionFactory from a Reference or environment Hashtable
      java.lang.Object createDestination​(javax.naming.Reference ref, java.util.Hashtable<?,​?> environment, javax.naming.Name name, boolean topic)
      Create a RMQDestination from a Reference of environment Hashtable
      java.lang.Object getObjectInstance​(java.lang.Object obj, javax.naming.Name name, javax.naming.Context ctx, java.util.Hashtable<?,​?> environment)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RMQObjectFactory

        public RMQObjectFactory()
    • Method Detail

      • getObjectInstance

        public java.lang.Object getObjectInstance​(java.lang.Object obj,
                                                  javax.naming.Name name,
                                                  javax.naming.Context ctx,
                                                  java.util.Hashtable<?,​?> environment)
                                           throws java.lang.Exception
        Specified by:
        getObjectInstance in interface javax.naming.spi.ObjectFactory
        Throws:
        java.lang.Exception
      • createConnectionFactory

        public java.lang.Object createConnectionFactory​(javax.naming.Reference ref,
                                                        java.util.Hashtable<?,​?> environment,
                                                        javax.naming.Name name)
                                                 throws javax.naming.NamingException
        Creates a RMQConnectionFactory from a Reference or environment Hashtable
        Parameters:
        ref - the reference containing properties
        environment - the environment containing properties
        name - the name of the object
        Returns:
        a RMQConnectionFactory object configured
        Throws:
        javax.naming.NamingException - if a required property is missing or invalid
      • createDestination

        public java.lang.Object createDestination​(javax.naming.Reference ref,
                                                  java.util.Hashtable<?,​?> environment,
                                                  javax.naming.Name name,
                                                  boolean topic)
                                           throws javax.naming.NamingException
        Create a RMQDestination from a Reference of environment Hashtable
        Parameters:
        ref - the reference containing the properties
        environment - the environment containing the properties
        name - the name
        topic - true if this is a topic, false if it is a queue (ignored if this is amqp-mapped)
        Returns:
        a RMQDestination object with the destinationName configured
        Throws:
        javax.naming.NamingException - if the destinationName property is missing