- java.lang.Object
-
- com.rabbitmq.jms.admin.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.TopicConnectionFactoryRabbitMQ Implementation of JMSConnectionFactoryTODO - implement SslContext option- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RMQConnectionFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description jakarta.jms.ConnectioncreateConnection()jakarta.jms.ConnectioncreateConnection(java.lang.String username, java.lang.String password)protected jakarta.jms.ConnectioncreateConnection(java.lang.String username, java.lang.String password, com.rabbitmq.jms.admin.RMQConnectionFactory.ConnectionCreator connectionCreator)jakarta.jms.ConnectioncreateConnection(java.lang.String username, java.lang.String password, java.util.List<com.rabbitmq.client.Address> endpoints)jakarta.jms.ConnectioncreateConnection(java.util.List<com.rabbitmq.client.Address> endpoints)protected com.rabbitmq.client.ConnectionFactorycreateConnectionFactory()jakarta.jms.JMSContextcreateContext()jakarta.jms.JMSContextcreateContext(int sessionMode)jakarta.jms.JMSContextcreateContext(java.lang.String username, java.lang.String password)jakarta.jms.JMSContextcreateContext(java.lang.String username, java.lang.String password, int sessionMode)jakarta.jms.QueueConnectioncreateQueueConnection()jakarta.jms.QueueConnectioncreateQueueConnection(java.lang.String userName, java.lang.String password)jakarta.jms.TopicConnectioncreateTopicConnection()jakarta.jms.TopicConnectioncreateTopicConnection(java.lang.String userName, java.lang.String password)intgetChannelsQos()QoS setting for channels created by this connection factory.java.lang.StringgetHost()Returns the host name to be used when creating a connection to the RabbitMQ broker.intgetOnMessageTimeoutMs()Returns the time in millisecondsMessageListener.onMessage(Message)can take to process a messagejava.lang.StringgetPassword()Returns the configured password used when creating a connection IfsetPassword(String)has not been called the default value of 'guest' is returned.intgetPort()Returns the port the RabbitMQ broker listens to; this port is used to connect to the broker.intgetQueueBrowserReadMax()Returns the maximum number of messages to read on a queue browser, or zero if there is no limit.javax.naming.ReferencegetReference()ReplyToStrategygetReplyToStrategy()Gets ths reply to strategy to use when receiving messages with a reply-to specified.longgetTerminationTimeout()Returns the time to wait in milliseconds whenConnection.close()has been called for listeners and threads to complete.java.util.List<java.lang.String>getTrustedPackages()java.lang.StringgetUri()Returns the current factory connection parameters in a URI String.java.util.List<java.lang.String>getUris()java.lang.StringgetUsername()Returns the configured username used when creating a connection IfsetUsername(String)has not been called the default value of 'guest' is returned.java.lang.StringgetVirtualHost()Returns the virtual host used when creating a connection.booleanisCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose()booleanisNackOnRollback()booleanisPreferProducerMessageProperty()booleanisRequeueOnMessageListenerException()booleanisSsl()booleanisUseDefaultSslContext()Whether to use the defaultSSLContextor not.voidsetAmqpConnectionFactoryPostProcessor(java.util.function.Consumer<com.rabbitmq.client.ConnectionFactory> amqpConnectionFactoryPostProcessor)Set a post-processor for the AMQPConnectionFactory.voidsetAmqpPropertiesCustomiser(java.util.function.BiFunction<com.rabbitmq.client.AMQP.BasicProperties.Builder,jakarta.jms.Message,com.rabbitmq.client.AMQP.BasicProperties.Builder> amqpPropertiesCustomiser)voidsetAuthenticationMechanism(AuthenticationMechanism authenticationMechanism)Sets the authentication mechanism to use.voidsetChannelsQos(int channelsQos)QoS setting for channels created by this connection factory.voidsetCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose(boolean cleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose)voidsetDeclareReplyToDestination(boolean declareReplyToDestination)WhetherreplyTodestination for consumed messages should be declared.voidsetHost(java.lang.String host)Sets the host of the RabbitMQ broker.voidsetHostnameVerification(boolean hostnameVerification)Enable or disable hostname verification when TLS is used.voidsetKeepTextMessageType(boolean keepTextMessageType)voidsetMetricsCollector(com.rabbitmq.client.MetricsCollector metricsCollector)Set the collector for AMQP-client metrics.voidsetNackOnRollback(boolean nackOnRollback)Whether to nack messages on rollback or not.voidsetOnMessageTimeoutMs(int onMessageTimeoutMs)Sets onMessageTimeoutMs: the time in millisecondsMessageListener.onMessage(Message)can take to process a message.voidsetPassword(java.lang.String password)Sets the password to be used when creating a connection to the RabbitMQ brokervoidsetPort(int port)Set the port to be used when making a connection to the RabbitMQ broker.voidsetPreferProducerMessageProperty(boolean preferProducerMessageProperty)WhetherMessageProducerproperties (delivery mode, priority, TTL) take precedence over respectiveMessageproperties or not.voidsetQueueBrowserReadMax(int queueBrowserReadMax)Sets queueBrowserReadMax: the maximum number of messages to read on a queue browser.voidsetReceivingContextConsumer(ReceivingContextConsumer receivingContextConsumer)Set callback called before dispatching a received message to application code.voidsetReplyToStrategy(ReplyToStrategy replyToStrategy)Sets the strategy to use when receiving messages with a reply-to specified.voidsetRequeueOnMessageListenerException(boolean requeueOnMessageListenerException)Whether requeue message onRuntimeExceptionin theMessageListeneror not.voidsetRequeueOnTimeout(boolean requeueOnTimeout)Whether to requeue a message that timed out or not.voidsetSendingContextConsumer(SendingContextConsumer sendingContextConsumer)Set callback called before sending a message.voidsetSsl(boolean ssl)Deprecated.voidsetTerminationTimeout(long terminationTimeout)Sets terminationTimeout: the time in milliseconds aConnection.close()should wait for threads/tasks/listeners to completevoidsetTrustedPackages(java.util.List<java.lang.String> value)voidsetUri(java.lang.String uriString)Set connection factory parameters by URI String.voidsetUris(java.util.List<java.lang.String> urisAsStrings)Sets the nodes URIs to connect to.voidsetUseDefaultSslContext(boolean useDefaultSslContext)Whether to use the defaultSSLContextor not.voidsetUsername(java.lang.String username)Sets the username to be used when creating a connection to the RabbitMQ broker.voidsetVirtualHost(java.lang.String virtualHost)Sets the virtualHost to be used when creating a connection to the RabbitMQ broker.java.lang.StringtoString()voiduseDefaultSslContext(boolean useDefaultSslContext)Whether to use the defaultSSLContextor not.voiduseSslProtocol()Enables TLS on opened connections with the highest TLS version available.voiduseSslProtocol(java.lang.String protocol)Enables TLS on opened connections using the provided TLS protocol version.voiduseSslProtocol(javax.net.ssl.SSLContext context)Enables TLS on opened connections using the providedSSLContext.
-
-
-
Method Detail
-
createConnection
public jakarta.jms.Connection createConnection() throws jakarta.jms.JMSException- Specified by:
createConnectionin interfacejakarta.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:
createConnectionin interfacejakarta.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:
toStringin classjava.lang.Object
-
setUri
public void setUri(java.lang.String uriString) throws jakarta.jms.JMSExceptionSet 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.JMSExceptionSets 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()
-
setSsl
@Deprecated public void setSsl(boolean ssl)
Deprecated.- Parameters:
ssl- if true, enables TLS for connections opened
-
useSslProtocol
public void useSslProtocol() throws java.security.NoSuchAlgorithmExceptionEnables TLS on opened connections with the highest TLS version available.- Throws:
java.security.NoSuchAlgorithmException- seeNoSuchAlgorithmException
-
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 providedSSLContext.- Parameters:
context-SSLContextto use
-
useDefaultSslContext
public void useDefaultSslContext(boolean useDefaultSslContext)
Whether to use the defaultSSLContextor not. Default is false. When this option is enabled, the defaultSSLContextwill always be used and will override any otherSSLContextset.- Parameters:
useDefaultSslContext-- See Also:
SSLContext.getDefault()
-
isUseDefaultSslContext
public boolean isUseDefaultSslContext()
Whether to use the defaultSSLContextor not.- See Also:
SSLContext.getDefault()
-
setUseDefaultSslContext
public void setUseDefaultSslContext(boolean useDefaultSslContext)
Whether to use the defaultSSLContextor not. Default is false. When this option is enabled, the defaultSSLContextwill always be used and will override any otherSSLContextset.- Parameters:
useDefaultSslContext-- See Also:
SSLContext.getDefault()
-
getReference
public javax.naming.Reference getReference() throws javax.naming.NamingException- Specified by:
getReferencein interfacejavax.naming.Referenceable- Throws:
javax.naming.NamingException
-
createTopicConnection
public jakarta.jms.TopicConnection createTopicConnection() throws jakarta.jms.JMSException- Specified by:
createTopicConnectionin interfacejakarta.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:
createTopicConnectionin interfacejakarta.jms.TopicConnectionFactory- Throws:
jakarta.jms.JMSException
-
createQueueConnection
public jakarta.jms.QueueConnection createQueueConnection() throws jakarta.jms.JMSException- Specified by:
createQueueConnectionin interfacejakarta.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:
createQueueConnectionin interfacejakarta.jms.QueueConnectionFactory- Throws:
jakarta.jms.JMSException
-
getUsername
public java.lang.String getUsername()
Returns the configured username used when creating a connection IfsetUsername(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 isnullthe 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 IfsetPassword(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. IfsetVirtualHost(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 isnullthe 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 isnullthe 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 whenConnection.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 aConnection.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 millisecondsMessageListener.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 millisecondsMessageListener.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)
WhetherMessageProducerproperties (delivery mode, priority, TTL) take precedence over respectiveMessageproperties 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 onRuntimeExceptionin theMessageListeneror 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 AMQPConnectionFactory.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)
WhetherreplyTodestination for consumed messages should be declared.Default is
true. Set this value tofalsefor 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:
createContextin interfacejakarta.jms.ConnectionFactory
-
createContext
public jakarta.jms.JMSContext createContext(java.lang.String username, java.lang.String password)- Specified by:
createContextin interfacejakarta.jms.ConnectionFactory
-
createContext
public jakarta.jms.JMSContext createContext(java.lang.String username, java.lang.String password, int sessionMode)- Specified by:
createContextin interfacejakarta.jms.ConnectionFactory
-
createContext
public jakarta.jms.JMSContext createContext(int sessionMode)
- Specified by:
createContextin interfacejakarta.jms.ConnectionFactory
-
-