Class RMQConnectionFactory

  • All Implemented Interfaces:
    jakarta.jms.ConnectionFactory, jakarta.jms.QueueConnectionFactory, jakarta.jms.TopicConnectionFactory, java.io.Serializable, javax.naming.Referenceable

    public class RMQConnectionFactory
    extends java.lang.Object
    implements jakarta.jms.ConnectionFactory, javax.naming.Referenceable, java.io.Serializable, jakarta.jms.QueueConnectionFactory, jakarta.jms.TopicConnectionFactory
    RabbitMQ Implementation of JMS ConnectionFactory TODO - implement SslContext option
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      jakarta.jms.Connection createConnection()
      jakarta.jms.Connection createConnection​(java.lang.String username, java.lang.String password)
      protected jakarta.jms.Connection createConnection​(java.lang.String username, java.lang.String password, com.rabbitmq.jms.admin.RMQConnectionFactory.ConnectionCreator connectionCreator)  
      jakarta.jms.Connection createConnection​(java.lang.String username, java.lang.String password, java.util.List<com.rabbitmq.client.Address> endpoints)  
      jakarta.jms.Connection createConnection​(java.util.List<com.rabbitmq.client.Address> endpoints)  
      protected com.rabbitmq.client.ConnectionFactory createConnectionFactory()  
      jakarta.jms.JMSContext createContext()  
      jakarta.jms.JMSContext createContext​(int sessionMode)  
      jakarta.jms.JMSContext createContext​(java.lang.String username, java.lang.String password)  
      jakarta.jms.JMSContext createContext​(java.lang.String username, java.lang.String password, int sessionMode)  
      jakarta.jms.QueueConnection createQueueConnection()
      jakarta.jms.QueueConnection createQueueConnection​(java.lang.String userName, java.lang.String password)
      jakarta.jms.TopicConnection createTopicConnection()
      jakarta.jms.TopicConnection createTopicConnection​(java.lang.String userName, java.lang.String password)
      int getChannelsQos()
      QoS setting for channels created by this connection factory.
      java.lang.String getHost()
      Returns the host name to be used when creating a connection to the RabbitMQ broker.
      int getOnMessageTimeoutMs()
      Returns the time in milliseconds MessageListener.onMessage(Message) can take to process a message
      java.lang.String getPassword()
      Returns the configured password used when creating a connection If setPassword(String) has not been called the default value of 'guest' is returned.
      int getPort()
      Returns the port the RabbitMQ broker listens to; this port is used to connect to the broker.
      int getQueueBrowserReadMax()
      Returns the maximum number of messages to read on a queue browser, or zero if there is no limit.
      javax.naming.Reference getReference()
      ReplyToStrategy getReplyToStrategy()
      Gets ths reply to strategy to use when receiving messages with a reply-to specified.
      long getTerminationTimeout()
      Returns the time to wait in milliseconds when Connection.close() has been called for listeners and threads to complete.
      java.util.List<java.lang.String> getTrustedPackages()  
      java.lang.String getUri()
      Returns the current factory connection parameters in a URI String.
      java.util.List<java.lang.String> getUris()  
      java.lang.String getUsername()
      Returns the configured username used when creating a connection If setUsername(String) has not been called the default value of 'guest' is returned.
      java.lang.String getVirtualHost()
      Returns the virtual host used when creating a connection.
      boolean isCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose()  
      boolean isNackOnRollback()  
      boolean isPreferProducerMessageProperty()  
      boolean isRequeueOnMessageListenerException()  
      boolean isSsl()  
      boolean isUseDefaultSslContext()
      Whether to use the default SSLContext or not.
      void setAmqpConnectionFactoryPostProcessor​(java.util.function.Consumer<com.rabbitmq.client.ConnectionFactory> amqpConnectionFactoryPostProcessor)
      Set a post-processor for the AMQP ConnectionFactory.
      void setAmqpPropertiesCustomiser​(java.util.function.BiFunction<com.rabbitmq.client.AMQP.BasicProperties.Builder,​jakarta.jms.Message,​com.rabbitmq.client.AMQP.BasicProperties.Builder> amqpPropertiesCustomiser)  
      void setAuthenticationMechanism​(AuthenticationMechanism authenticationMechanism)
      Sets the authentication mechanism to use.
      void setChannelsQos​(int channelsQos)
      QoS setting for channels created by this connection factory.
      void setCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose​(boolean cleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose)  
      void setDeclareReplyToDestination​(boolean declareReplyToDestination)
      Whether replyTo destination for consumed messages should be declared.
      void setHost​(java.lang.String host)
      Sets the host of the RabbitMQ broker.
      void setHostnameVerification​(boolean hostnameVerification)
      Enable or disable hostname verification when TLS is used.
      void setKeepTextMessageType​(boolean keepTextMessageType)  
      void setMetricsCollector​(com.rabbitmq.client.MetricsCollector metricsCollector)
      Set the collector for AMQP-client metrics.
      void setNackOnRollback​(boolean nackOnRollback)
      Whether to nack messages on rollback or not.
      void setOnMessageTimeoutMs​(int onMessageTimeoutMs)
      Sets onMessageTimeoutMs: the time in milliseconds MessageListener.onMessage(Message) can take to process a message.
      void setPassword​(java.lang.String password)
      Sets the password to be used when creating a connection to the RabbitMQ broker
      void setPort​(int port)
      Set the port to be used when making a connection to the RabbitMQ broker.
      void setPreferProducerMessageProperty​(boolean preferProducerMessageProperty)
      Whether MessageProducer properties (delivery mode, priority, TTL) take precedence over respective Message properties or not.
      void setQueueBrowserReadMax​(int queueBrowserReadMax)
      Sets queueBrowserReadMax: the maximum number of messages to read on a queue browser.
      void setReceivingContextConsumer​(ReceivingContextConsumer receivingContextConsumer)
      Set callback called before dispatching a received message to application code.
      void setReplyToStrategy​(ReplyToStrategy replyToStrategy)
      Sets the strategy to use when receiving messages with a reply-to specified.
      void setRequeueOnMessageListenerException​(boolean requeueOnMessageListenerException)
      Whether requeue message on RuntimeException in the MessageListener or not.
      void setRequeueOnTimeout​(boolean requeueOnTimeout)
      Whether to requeue a message that timed out or not.
      void setSendingContextConsumer​(SendingContextConsumer sendingContextConsumer)
      Set callback called before sending a message.
      void setSsl​(boolean ssl)
      void setTerminationTimeout​(long terminationTimeout)
      Sets terminationTimeout: the time in milliseconds a Connection.close() should wait for threads/tasks/listeners to complete
      void setTrustedPackages​(java.util.List<java.lang.String> value)  
      void setUri​(java.lang.String uriString)
      Set connection factory parameters by URI String.
      void setUris​(java.util.List<java.lang.String> urisAsStrings)
      Sets the nodes URIs to connect to.
      void setUseDefaultSslContext​(boolean useDefaultSslContext)
      Whether to use the default SSLContext or not.
      void setUsername​(java.lang.String username)
      Sets the username to be used when creating a connection to the RabbitMQ broker.
      void setVirtualHost​(java.lang.String virtualHost)
      Sets the virtualHost to be used when creating a connection to the RabbitMQ broker.
      java.lang.String toString()  
      void useDefaultSslContext​(boolean useDefaultSslContext)
      Whether to use the default SSLContext or not.
      void useSslProtocol()
      Enables TLS on opened connections with the highest TLS version available.
      void useSslProtocol​(java.lang.String protocol)
      Enables TLS on opened connections using the provided TLS protocol version.
      void useSslProtocol​(javax.net.ssl.SSLContext context)
      Enables TLS on opened connections using the provided SSLContext.
      • Methods inherited from class java.lang.Object

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

      • RMQConnectionFactory

        public RMQConnectionFactory()
    • Method Detail

      • createConnection

        public jakarta.jms.Connection createConnection()
                                                throws jakarta.jms.JMSException
        Specified by:
        createConnection in interface jakarta.jms.ConnectionFactory
        Throws:
        jakarta.jms.JMSException
      • createConnection

        public jakarta.jms.Connection createConnection​(java.util.List<com.rabbitmq.client.Address> endpoints)
                                                throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • createConnection

        public jakarta.jms.Connection createConnection​(java.lang.String username,
                                                       java.lang.String password)
                                                throws jakarta.jms.JMSException
        Specified by:
        createConnection in interface jakarta.jms.ConnectionFactory
        Throws:
        jakarta.jms.JMSException
      • createConnection

        public jakarta.jms.Connection createConnection​(java.lang.String username,
                                                       java.lang.String password,
                                                       java.util.List<com.rabbitmq.client.Address> endpoints)
                                                throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • createConnection

        protected jakarta.jms.Connection createConnection​(java.lang.String username,
                                                          java.lang.String password,
                                                          com.rabbitmq.jms.admin.RMQConnectionFactory.ConnectionCreator connectionCreator)
                                                   throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • createConnectionFactory

        protected com.rabbitmq.client.ConnectionFactory createConnectionFactory()
      • getUri

        public java.lang.String getUri()
        Returns the current factory connection parameters in a URI String.
        Returns:
        URI for RabbitMQ connection (as a coded String)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • setUri

        public void setUri​(java.lang.String uriString)
                    throws jakarta.jms.JMSException
        Set connection factory parameters by URI String.
        Parameters:
        uriString - URI to use for instantiated connection
        Throws:
        jakarta.jms.JMSException - if connection URI is invalid
      • setUris

        public void setUris​(java.util.List<java.lang.String> urisAsStrings)
                     throws jakarta.jms.JMSException
        Sets the nodes URIs to connect to.
        Parameters:
        urisAsStrings -
        Throws:
        jakarta.jms.JMSException
        Since:
        1.10.0
      • setTrustedPackages

        public void setTrustedPackages​(java.util.List<java.lang.String> value)
        Parameters:
        value - list of trusted package prefixes
      • getTrustedPackages

        public java.util.List<java.lang.String> getTrustedPackages()
        Returns:
        list of package prefixes that are whitelisted for transfer over ObjectMessage
      • isSsl

        public boolean isSsl()
      • useSslProtocol

        public void useSslProtocol()
                            throws java.security.NoSuchAlgorithmException
        Enables TLS on opened connections with the highest TLS version available.
        Throws:
        java.security.NoSuchAlgorithmException - see NoSuchAlgorithmException
      • useSslProtocol

        public void useSslProtocol​(java.lang.String protocol)
        Enables TLS on opened connections using the provided TLS protocol version.
        Parameters:
        protocol - TLS or SSL protocol version.
        See Also:
        JDK documentation on protocol names
      • useSslProtocol

        public void useSslProtocol​(javax.net.ssl.SSLContext context)
        Enables TLS on opened connections using the provided SSLContext.
        Parameters:
        context - SSLContext to use
      • useDefaultSslContext

        public void useDefaultSslContext​(boolean useDefaultSslContext)
        Whether to use the default SSLContext or not. Default is false. When this option is enabled, the default SSLContext will always be used and will override any other SSLContext set.
        Parameters:
        useDefaultSslContext -
        See Also:
        SSLContext.getDefault()
      • isUseDefaultSslContext

        public boolean isUseDefaultSslContext()
        Whether to use the default SSLContext or not.
        See Also:
        SSLContext.getDefault()
      • setUseDefaultSslContext

        public void setUseDefaultSslContext​(boolean useDefaultSslContext)
        Whether to use the default SSLContext or not. Default is false. When this option is enabled, the default SSLContext will always be used and will override any other SSLContext set.
        Parameters:
        useDefaultSslContext -
        See Also:
        SSLContext.getDefault()
      • getReference

        public javax.naming.Reference getReference()
                                            throws javax.naming.NamingException
        Specified by:
        getReference in interface javax.naming.Referenceable
        Throws:
        javax.naming.NamingException
      • createTopicConnection

        public jakarta.jms.TopicConnection createTopicConnection()
                                                          throws jakarta.jms.JMSException
        Specified by:
        createTopicConnection in interface jakarta.jms.TopicConnectionFactory
        Throws:
        jakarta.jms.JMSException
      • createTopicConnection

        public jakarta.jms.TopicConnection createTopicConnection​(java.lang.String userName,
                                                                 java.lang.String password)
                                                          throws jakarta.jms.JMSException
        Specified by:
        createTopicConnection in interface jakarta.jms.TopicConnectionFactory
        Throws:
        jakarta.jms.JMSException
      • createQueueConnection

        public jakarta.jms.QueueConnection createQueueConnection()
                                                          throws jakarta.jms.JMSException
        Specified by:
        createQueueConnection in interface jakarta.jms.QueueConnectionFactory
        Throws:
        jakarta.jms.JMSException
      • createQueueConnection

        public jakarta.jms.QueueConnection createQueueConnection​(java.lang.String userName,
                                                                 java.lang.String password)
                                                          throws jakarta.jms.JMSException
        Specified by:
        createQueueConnection in interface jakarta.jms.QueueConnectionFactory
        Throws:
        jakarta.jms.JMSException
      • getUsername

        public java.lang.String getUsername()
        Returns the configured username used when creating a connection If setUsername(String) has not been called the default value of 'guest' is returned.
        Returns:
        a string representing the username for a RabbitMQ connection
      • setUsername

        public void setUsername​(java.lang.String username)
        Sets the username to be used when creating a connection to the RabbitMQ broker. If the parameter is null the current username is not changed.
        Parameters:
        username - - username to be used when creating a connection to the RabbitMQ broker
      • getPassword

        public java.lang.String getPassword()
        Returns the configured password used when creating a connection If setPassword(String) has not been called the default value of 'guest' is returned.
        Returns:
        a string representing the password for a Rabbit connection
      • setPassword

        public void setPassword​(java.lang.String password)
        Sets the password to be used when creating a connection to the RabbitMQ broker
        Parameters:
        password - - password to be used when creating a connection to the RabbitMQ broker
      • getVirtualHost

        public java.lang.String getVirtualHost()
        Returns the virtual host used when creating a connection. If setVirtualHost(String) has not been called the default value of '/' is returned.
        Returns:
        a String representing the virtual host for a RabbitMQ connection
      • setVirtualHost

        public void setVirtualHost​(java.lang.String virtualHost)
        Sets the virtualHost to be used when creating a connection to the RabbitMQ broker. If the parameter is null the current virtualHost is not changed.
        Parameters:
        virtualHost - - virtual host to be used when creating a connection to the RabbitMQ broker
      • getHost

        public java.lang.String getHost()
        Returns the host name to be used when creating a connection to the RabbitMQ broker.
        Returns:
        the host name of the RabbitMQ broker
      • setHost

        public void setHost​(java.lang.String host)
        Sets the host of the RabbitMQ broker. The host name can be an IP address or a host name. If the parameter is null the current host name is not changed.
        Parameters:
        host - - IP address or a host name of the RabbitMQ broker, in String form
      • getPort

        public int getPort()
        Returns the port the RabbitMQ broker listens to; this port is used to connect to the broker. If the port has not been set (defaults to -1) then the default port for this type of connection is returned.
        Returns:
        the port the RabbitMQ broker listens to
      • setPort

        public void setPort​(int port)
        Set the port to be used when making a connection to the RabbitMQ broker. This is the port number the broker will listen on. Setting this to -1 means take the RabbitMQ default (which depends on the type of connection).
        Parameters:
        port - - a TCP port number
      • getTerminationTimeout

        public long getTerminationTimeout()
        Returns the time to wait in milliseconds when Connection.close() has been called for listeners and threads to complete.
        Returns:
        the duration in milliseconds for which the Connection.close() waits before continuing shutdown sequence
      • setTerminationTimeout

        public void setTerminationTimeout​(long terminationTimeout)
        Sets terminationTimeout: the time in milliseconds a Connection.close() should wait for threads/tasks/listeners to complete
        Parameters:
        terminationTimeout - - duration in milliseconds
      • getQueueBrowserReadMax

        public int getQueueBrowserReadMax()
        Returns the maximum number of messages to read on a queue browser, or zero if there is no limit.
        Returns:
        the maximum number of messages to read on a queue browser
      • setQueueBrowserReadMax

        public void setQueueBrowserReadMax​(int queueBrowserReadMax)
        Sets queueBrowserReadMax: the maximum number of messages to read on a queue browser. Non-positive values are set to zero, which is interpreted as no limit.
        Parameters:
        queueBrowserReadMax - - read no more than this number of messages on a queue browser.
      • getOnMessageTimeoutMs

        public int getOnMessageTimeoutMs()
        Returns the time in milliseconds MessageListener.onMessage(Message) can take to process a message
        Returns:
        the time in milliseconds MessageListener.onMessage(Message) can take to process a message
      • setOnMessageTimeoutMs

        public void setOnMessageTimeoutMs​(int onMessageTimeoutMs)
        Sets onMessageTimeoutMs: the time in milliseconds MessageListener.onMessage(Message) can take to process a message. Non-positive values are rejected.
        Parameters:
        onMessageTimeoutMs - - duration in milliseconds
      • getChannelsQos

        public int getChannelsQos()
        QoS setting for channels created by this connection factory.
        See Also:
        Channel.basicQos(int)
      • setChannelsQos

        public void setChannelsQos​(int channelsQos)
        QoS setting for channels created by this connection factory.
        Parameters:
        channelsQos - maximum number of messages that the server will deliver, 0 if unlimited
        See Also:
        Channel.basicQos(int)
      • setPreferProducerMessageProperty

        public void setPreferProducerMessageProperty​(boolean preferProducerMessageProperty)
        Whether MessageProducer properties (delivery mode, priority, TTL) take precedence over respective Message properties or not. Default is true (which is compliant to the JMS specification).
      • isPreferProducerMessageProperty

        public boolean isPreferProducerMessageProperty()
      • setRequeueOnMessageListenerException

        public void setRequeueOnMessageListenerException​(boolean requeueOnMessageListenerException)
        Whether requeue message on RuntimeException in the MessageListener or not. Default is false.
        Since:
        1.7.0
        See Also:
        setRequeueOnTimeout(boolean)
      • isRequeueOnMessageListenerException

        public boolean isRequeueOnMessageListenerException()
      • setNackOnRollback

        public void setNackOnRollback​(boolean nackOnRollback)
        Whether to nack messages on rollback or not. Nack-ed messages will be discarded, not re-queued. Queues will typically have dead lettering configured when enabling this feature, so nack-ed messages are routed elsewhere and not discarded forever.

        Default is false.

        Parameters:
        nackOnRollback - true to nack and discard messages on rollback, false to requeue them
        Since:
        1.14.0
        See Also:
        Negative Acknowledgements, Dead Letter Exchanges
      • isNackOnRollback

        public boolean isNackOnRollback()
      • setCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose

        public void setCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose​(boolean cleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose)
      • isCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose

        public boolean isCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose()
      • setAmqpPropertiesCustomiser

        public void setAmqpPropertiesCustomiser​(java.util.function.BiFunction<com.rabbitmq.client.AMQP.BasicProperties.Builder,​jakarta.jms.Message,​com.rabbitmq.client.AMQP.BasicProperties.Builder> amqpPropertiesCustomiser)
      • setHostnameVerification

        public void setHostnameVerification​(boolean hostnameVerification)
        Enable or disable hostname verification when TLS is used.
        Parameters:
        hostnameVerification -
        Since:
        1.10.0
        See Also:
        ConnectionFactory.enableHostnameVerification()
      • setMetricsCollector

        public void setMetricsCollector​(com.rabbitmq.client.MetricsCollector metricsCollector)
        Set the collector for AMQP-client metrics.
        Parameters:
        metricsCollector -
        Since:
        1.10.0
        See Also:
        ConnectionFactory.setMetricsCollector(MetricsCollector)
      • getUris

        public java.util.List<java.lang.String> getUris()
      • setAmqpConnectionFactoryPostProcessor

        public void setAmqpConnectionFactoryPostProcessor​(java.util.function.Consumer<com.rabbitmq.client.ConnectionFactory> amqpConnectionFactoryPostProcessor)
        Set a post-processor for the AMQP ConnectionFactory.

        The post-processor is called before the AMQP connection creation. This callback can be useful to customize the ConnectionFactory: TLS-related configuration, metrics collection, etc.

        Parameters:
        amqpConnectionFactoryPostProcessor -
        Since:
        1.10.0
      • setSendingContextConsumer

        public void setSendingContextConsumer​(SendingContextConsumer sendingContextConsumer)
        Set callback called before sending a message. Can be used to customize the message or the destination before the message is actually sent.
        Since:
        1.11.0
        See Also:
        SendingContextConsumer, SendingContext
      • setReceivingContextConsumer

        public void setReceivingContextConsumer​(ReceivingContextConsumer receivingContextConsumer)
        Set callback called before dispatching a received message to application code. Can be used to customize messages before they handed over application.
        Parameters:
        receivingContextConsumer -
        Since:
        1.11.0
        See Also:
        ReceivingContextConsumer
      • setDeclareReplyToDestination

        public void setDeclareReplyToDestination​(boolean declareReplyToDestination)
        Whether replyTo destination for consumed messages should be declared.

        Default is true. Set this value to false for the server-side of RPC, this avoids creating a temporary reply-to destination on both client and server, leading to an error.

        This is implemented as ReceivingContextConsumer.

        Since:
        1.11.0
        See Also:
        setReceivingContextConsumer(ReceivingContextConsumer)
      • setReplyToStrategy

        public void setReplyToStrategy​(ReplyToStrategy replyToStrategy)
        Sets the strategy to use when receiving messages with a reply-to specified.
        Parameters:
        replyToStrategy - The reply to strategy.
      • getReplyToStrategy

        public ReplyToStrategy getReplyToStrategy()
        Gets ths reply to strategy to use when receiving messages with a reply-to specified.
        Returns:
        The strategy.
      • setAuthenticationMechanism

        public void setAuthenticationMechanism​(AuthenticationMechanism authenticationMechanism)
        Sets the authentication mechanism to use.
        Parameters:
        authenticationMechanism - authentication mechanism
      • setRequeueOnTimeout

        public void setRequeueOnTimeout​(boolean requeueOnTimeout)
        Whether to requeue a message that timed out or not. Only taken into account if requeueOnMessageListenerException is true. Default is false.
        Since:
        2.3.0
        See Also:
        setRequeueOnMessageListenerException(boolean)
      • setKeepTextMessageType

        public void setKeepTextMessageType​(boolean keepTextMessageType)
      • createContext

        public jakarta.jms.JMSContext createContext()
        Specified by:
        createContext in interface jakarta.jms.ConnectionFactory
      • createContext

        public jakarta.jms.JMSContext createContext​(java.lang.String username,
                                                    java.lang.String password)
        Specified by:
        createContext in interface jakarta.jms.ConnectionFactory
      • createContext

        public jakarta.jms.JMSContext createContext​(java.lang.String username,
                                                    java.lang.String password,
                                                    int sessionMode)
        Specified by:
        createContext in interface jakarta.jms.ConnectionFactory
      • createContext

        public jakarta.jms.JMSContext createContext​(int sessionMode)
        Specified by:
        createContext in interface jakarta.jms.ConnectionFactory