Class JmsConnectionFactory
- All Implemented Interfaces:
jakarta.jms.ConnectionFactory,jakarta.jms.QueueConnectionFactory,jakarta.jms.TopicConnectionFactory,Externalizable,Serializable,Referenceable
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJmsConnectionFactory(String remoteURI) JmsConnectionFactory(String username, String password) JmsConnectionFactory(String userName, String password, String remoteURI) JmsConnectionFactory(String userName, String password, URI remoteURI) JmsConnectionFactory(URI remoteURI) -
Method Summary
Modifier and TypeMethodDescriptionbuildFromProperties(Map<String, String> props) Set the properties that will represent the instance in JNDIprotected JmsConnectionInfoconfigureConnectionInfo(String username, String password) jakarta.jms.Connectionjakarta.jms.ConnectioncreateConnection(String username, String password) jakarta.jms.JMSContextjakarta.jms.JMSContextcreateContext(int sessionMode) jakarta.jms.JMSContextcreateContext(String username, String password) jakarta.jms.JMSContextcreateContext(String username, String password, int sessionMode) protected ProvidercreateProvider(URI remoteURI) jakarta.jms.QueueConnectionjakarta.jms.QueueConnectioncreateQueueConnection(String username, String password) jakarta.jms.TopicConnectionjakarta.jms.TopicConnectioncreateTopicConnection(String username, String password) protected static URIprotected IdGeneratorlongGets the currently set close timeout.protected IdGeneratorlongReturns the currently configured wire level connect timeout.static Stringjakarta.jms.ExceptionListenerGets the currently configured JMS ExceptionListener that will be set on all new Connection objects created from this factory.Returns the prefix applied to Queues that are created by the client.Returns the JmsRedeliveryPolicy that is applied when a new connection is created.longlongReturns the prefix applied to Topics that are created by the client.Gets any tracer previously set explicitly on the connection factory usingsetTracer(JmsTracer).booleanbooleanbooleanbooleanbooleanReturns true if the client should always send messages using a synchronous send operation regardless of persistence mode, or inside a transaction.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanprotected voidpopulateProperties(Map<String, String> props) Initialize the instance from properties stored in JNDIvoidsetAwaitClientID(boolean awaitClientID) Controls whether the client will wait for a ClientID value to be set or the Connection to be used before it will attempt to complete the AMQP connection Open process.voidsetClientID(String clientID) Sets the JMS clientID to use for connections created by this factory.protected voidsetClientIdGenerator(IdGenerator clientIdGenerator) voidsetClientIDPrefix(String clientIDPrefix) Sets the prefix used by auto-generated JMS Client ID values which are used if the JMS client does not explicitly specify one.voidsetCloseLinksThatFailOnReconnect(boolean closeLinksThatFailOnReconnect) Controls how the client manages errors on recreation of a link (producer / consumer) during a failover reconnect attempt (defaults to false).voidsetCloseTimeout(long closeTimeout) Sets the close timeout used to control how long a Connection close will wait for clean shutdown of the connection before giving up.protected voidsetConnectionIdGenerator(IdGenerator connectionIdGenerator) voidsetConnectionIDPrefix(String connectionIDPrefix) Sets the prefix used by connection id generator.voidsetConnectTimeout(long connectTimeout) Sets the timeout value used to control how long a client will wait for a successful connection to the remote peer to be established before considering the attempt to have failed.voidsetDeserializationPolicy(JmsDeserializationPolicy deserializationPolicy) Sets the JmsDeserializationPolicy that is applied when a new connection is created.voidsetExceptionListener(jakarta.jms.ExceptionListener exceptionListener) Sets the JMS ExceptionListener that will be set on all new Connection objects created from this factory.voidsetExtension(String extensionName, BiFunction<jakarta.jms.Connection, URI, Object> extension) Provides an entry point for extensions to be configured on thisConnectionFactory.voidsetForceAsyncAcks(boolean forceAsyncAcks) Should the message acknowledgments from a consumer be sent synchronously or asynchronously.voidsetForceAsyncSend(boolean forceAsyncSend) voidsetForceSyncSend(boolean forceSyncSend) Configures whether or not the client will always send messages synchronously or not regardless of other factors that might result in an asynchronous send.voidsetLocalMessageExpiry(boolean localMessageExpiry) Controls whether message expiration checking is done locally (in addition to any broker side checks) in each MessageConsumer prior to dispatching a message.voidsetLocalMessagePriority(boolean localMessagePriority) Enables client-side message priority support in MessageConsumer instances.voidsetMessageIDPolicy(JmsMessageIDPolicy messageIDPolicy) Sets the JmsMessageIDPolicy that is use to configure the JmsMessageIDBuilder that is assigned to any new MessageProducer created from Connection instances that this factory has created.voidsetPassword(String password) voidsetPopulateJMSXUserID(boolean populateJMSXUserID) Controls whether message sent from the Connection will have the JMSXUserID message property populated with the authenticated user ID of the Connection.voidsetPrefetchPolicy(JmsPrefetchPolicy prefetchPolicy) voidsetPresettlePolicy(JmsPresettlePolicy presettlePolicy) Sets the JmsPresettlePolicy that is applied to MessageProducers.voidsetQueuePrefix(String queuePrefix) voidsetReceiveLocalOnly(boolean receiveLocalOnly) Controls whether the client only checks its local message buffer when using receive calls with a timeout, or will instead drain remaining credit from the remote peer to ensure there are really no messages available if the timeout expires before a message arrives in the consumers local buffer.voidsetReceiveNoWaitLocalOnly(boolean receiveNoWaitLocalOnly) Controls whether the client only checks its local message buffer when using receiveNoWait calls, or will instead drain remaining credit from the remote peer synchronously to ensure there are really no messages available that have yet to arrive in the consumers local buffer.voidsetRedeliveryPolicy(JmsRedeliveryPolicy redeliveryPolicy) Sets the JmsRedeliveryPolicy that is applied when a new connection is created.voidsetRemoteURI(String remoteURI) voidsetRequestTimeout(long requestTimeout) voidsetSendTimeout(long sendTimeout) voidsetSslContext(SSLContext sslContext) Sets an SSLContext to use when creating an SSL/TLS secured connection with this factory.voidsetTopicPrefix(String topicPrefix) voidExplicitly sets a tracer instance for use by the connection(s) created from the factory.voidsetTracing(String tracing) Sets the type name for a tracing provider to use for the connection(s) created using the factory.voidsetUseDaemonThread(boolean useDaemonThread) Sets whether the Connection created will ensure that there is at least one non-daemon thread running at all times.voidsetUsername(String username) voidsetValidatePropertyNames(boolean validatePropertyNames) voidsetValidateSelector(boolean validateSelector) Sets whether local validation is performed of a consumers message selector string conforming to the JMS selector syntax.Methods inherited from class org.apache.qpid.jms.jndi.JNDIStorable
getProperties, getProperty, getReference, readExternal, setProperties, writeExternal
-
Field Details
-
REMOTE_URI_PROP
- See Also:
-
-
Constructor Details
-
JmsConnectionFactory
public JmsConnectionFactory() -
JmsConnectionFactory
-
JmsConnectionFactory
-
JmsConnectionFactory
-
JmsConnectionFactory
-
JmsConnectionFactory
-
-
Method Details
-
buildFromProperties
Description copied from class:JNDIStorableSet the properties that will represent the instance in JNDI- Specified by:
buildFromPropertiesin classJNDIStorable- Parameters:
props- The properties to use when building the new isntance.- Returns:
- a new, unmodifiable, map containing any unused properties, or empty if none were.
-
populateProperties
Description copied from class:JNDIStorableInitialize the instance from properties stored in JNDI- Specified by:
populatePropertiesin classJNDIStorable- Parameters:
props- The properties to use when initializing the new instance.
-
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(String username, String password) throws jakarta.jms.JMSException - Specified by:
createTopicConnectionin interfacejakarta.jms.TopicConnectionFactory- Throws:
jakarta.jms.JMSException
-
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(String username, String password) throws jakarta.jms.JMSException - Specified by:
createConnectionin interfacejakarta.jms.ConnectionFactory- 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(String username, String password) throws jakarta.jms.JMSException - Specified by:
createQueueConnectionin interfacejakarta.jms.QueueConnectionFactory- Throws:
jakarta.jms.JMSException
-
configureConnectionInfo
protected JmsConnectionInfo configureConnectionInfo(String username, String password) throws jakarta.jms.JMSException - Throws:
jakarta.jms.JMSException
-
createContext
public jakarta.jms.JMSContext createContext()- Specified by:
createContextin interfacejakarta.jms.ConnectionFactory
-
createContext
public jakarta.jms.JMSContext createContext(int sessionMode) - Specified by:
createContextin interfacejakarta.jms.ConnectionFactory
-
createContext
- Specified by:
createContextin interfacejakarta.jms.ConnectionFactory
-
createContext
- Specified by:
createContextin interfacejakarta.jms.ConnectionFactory
-
createProvider
- Throws:
Exception
-
createURI
-
getConnectionIdGenerator
-
setConnectionIdGenerator
-
getRemoteURI
- Returns:
- the remoteURI
-
setRemoteURI
- Parameters:
remoteURI- the remoteURI to set
-
getUsername
- Returns:
- the user name used for connection authentication.
-
setUsername
- Parameters:
username- the user name to set
-
getPassword
- Returns:
- the password set for connection authentication.
-
setPassword
- Parameters:
password- the password to set
-
isForceSyncSend
public boolean isForceSyncSend()Returns true if the client should always send messages using a synchronous send operation regardless of persistence mode, or inside a transaction.- Returns:
- true if sends should always be done synchronously.
-
setForceSyncSend
public void setForceSyncSend(boolean forceSyncSend) Configures whether or not the client will always send messages synchronously or not regardless of other factors that might result in an asynchronous send.- Parameters:
forceSyncSend- if true sends are always done synchronously.
-
isForceAsyncSend
public boolean isForceAsyncSend() -
setForceAsyncSend
public void setForceAsyncSend(boolean forceAsyncSend) -
isLocalMessagePriority
public boolean isLocalMessagePriority()- Returns:
- the localMessagePriority configuration option.
-
setLocalMessagePriority
public void setLocalMessagePriority(boolean localMessagePriority) Enables client-side message priority support in MessageConsumer instances. This results in all prefetched messages being dispatched in priority order.- Parameters:
localMessagePriority- the messagePrioritySupported to set
-
getQueuePrefix
Returns the prefix applied to Queues that are created by the client.- Returns:
- the currently configured Queue prefix.
-
setQueuePrefix
-
getTopicPrefix
Returns the prefix applied to Topics that are created by the client.- Returns:
- the currently configured Topic prefix.
-
setTopicPrefix
-
isValidatePropertyNames
public boolean isValidatePropertyNames() -
setValidatePropertyNames
public void setValidatePropertyNames(boolean validatePropertyNames) -
isValidateSelector
public boolean isValidateSelector() -
setValidateSelector
public void setValidateSelector(boolean validateSelector) Sets whether local validation is performed of a consumers message selector string conforming to the JMS selector syntax. Default is true.- Parameters:
validateSelector- whether to validate consumer message selector strings
-
getCloseTimeout
public long getCloseTimeout()Gets the currently set close timeout.- Returns:
- the currently set close timeout.
-
setCloseTimeout
public void setCloseTimeout(long closeTimeout) Sets the close timeout used to control how long a Connection close will wait for clean shutdown of the connection before giving up. A negative value means wait forever. Care should be taken in that a very short close timeout can cause the client to not cleanly shutdown the connection and it's resources.- Parameters:
closeTimeout- time in milliseconds to wait for a clean connection close.
-
getConnectTimeout
public long getConnectTimeout()Returns the currently configured wire level connect timeout.- Returns:
- the currently configured wire level connect timeout.
-
setConnectTimeout
public void setConnectTimeout(long connectTimeout) Sets the timeout value used to control how long a client will wait for a successful connection to the remote peer to be established before considering the attempt to have failed. This value does not control socket level connection timeout but rather connection handshake at the wire level, to control the socket level timeouts use the standard socket options configuration values.- Parameters:
connectTimeout- the time in milliseconds to wait for the protocol connection handshake to complete.
-
getSendTimeout
public long getSendTimeout() -
setSendTimeout
public void setSendTimeout(long sendTimeout) -
getRequestTimeout
public long getRequestTimeout() -
setRequestTimeout
public void setRequestTimeout(long requestTimeout) -
getPrefetchPolicy
-
setPrefetchPolicy
-
getRedeliveryPolicy
Returns the JmsRedeliveryPolicy that is applied when a new connection is created.- Returns:
- the redeliveryPolicy that is currently configured for this factory.
-
setRedeliveryPolicy
Sets the JmsRedeliveryPolicy that is applied when a new connection is created.- Parameters:
redeliveryPolicy- The new redeliveryPolicy to set
-
getPresettlePolicy
- Returns:
- the presettlePolicy that is currently configured.
-
setPresettlePolicy
Sets the JmsPresettlePolicy that is applied to MessageProducers.- Parameters:
presettlePolicy- the presettlePolicy to use by connections created from this factory.
-
getMessageIDPolicy
- Returns:
- the messageIDPolicy that is currently configured.
-
setMessageIDPolicy
Sets the JmsMessageIDPolicy that is use to configure the JmsMessageIDBuilder that is assigned to any new MessageProducer created from Connection instances that this factory has created.- Parameters:
messageIDPolicy- the messageIDPolicy to use by connections created from this factory.
-
getDeserializationPolicy
- Returns:
- the deserializationPolicy that is currently configured.
-
setDeserializationPolicy
Sets the JmsDeserializationPolicy that is applied when a new connection is created.- Parameters:
deserializationPolicy- the deserializationPolicy that will be applied to new connections.
-
getClientIDPrefix
- Returns:
- the currently configured client ID prefix for auto-generated client IDs.
-
setClientIDPrefix
Sets the prefix used by auto-generated JMS Client ID values which are used if the JMS client does not explicitly specify one.- Parameters:
clientIDPrefix- the value to use as a prefix on auto-generated client IDs.
-
getClientIdGenerator
-
setClientIdGenerator
-
getClientID
-
setClientID
Sets the JMS clientID to use for connections created by this factory. NOTE: A clientID can only be used by one Connection at a time, so setting it here will restrict the ConnectionFactory to creating a single open Connection at a time. It is possible to set the clientID on the Connection itself immediately after creation if no value has been set via the factory that created it, which will allow the factory to create multiple open connections at a time.- Parameters:
clientID- The clientID to assign when creating a new connection.
-
setConnectionIDPrefix
Sets the prefix used by connection id generator.- Parameters:
connectionIDPrefix- The string prefix used on all connection Id's created by this factory.
-
getExceptionListener
public jakarta.jms.ExceptionListener getExceptionListener()Gets the currently configured JMS ExceptionListener that will be set on all new Connection objects created from this factory. NOTE: the listener object is not saved when serializing the factory.- Returns:
- the currently configured JMS ExceptionListener.
-
setExceptionListener
public void setExceptionListener(jakarta.jms.ExceptionListener exceptionListener) Sets the JMS ExceptionListener that will be set on all new Connection objects created from this factory.- Parameters:
exceptionListener- the JMS ExceptionListener to apply to new Connection's or null to clear.
-
isForceAsyncAcks
public boolean isForceAsyncAcks()- Returns:
- true if consumer acknowledgments are sent asynchronously or not.
-
setForceAsyncAcks
public void setForceAsyncAcks(boolean forceAsyncAcks) Should the message acknowledgments from a consumer be sent synchronously or asynchronously. Sending the acknowledgments asynchronously can increase the performance of a consumer but opens up the possibility of a missed message acknowledge should the connection be unstable.- Parameters:
forceAsyncAcks- true to have the client send all message acknowledgments asynchronously.
-
isLocalMessageExpiry
public boolean isLocalMessageExpiry()- Returns:
- true if MessageConsumer instance will check for expired messages locally before dispatch.
-
setLocalMessageExpiry
public void setLocalMessageExpiry(boolean localMessageExpiry) Controls whether message expiration checking is done locally (in addition to any broker side checks) in each MessageConsumer prior to dispatching a message. Disabling this check can lead to consumption of expired messages.- Parameters:
localMessageExpiry- controls whether expiration checking is done prior to dispatch.
-
isReceiveLocalOnly
public boolean isReceiveLocalOnly() -
setReceiveLocalOnly
public void setReceiveLocalOnly(boolean receiveLocalOnly) Controls whether the client only checks its local message buffer when using receive calls with a timeout, or will instead drain remaining credit from the remote peer to ensure there are really no messages available if the timeout expires before a message arrives in the consumers local buffer.- Parameters:
receiveLocalOnly- true if receive calls with a timeout should only check the local message buffer.
-
isReceiveNoWaitLocalOnly
public boolean isReceiveNoWaitLocalOnly() -
setReceiveNoWaitLocalOnly
public void setReceiveNoWaitLocalOnly(boolean receiveNoWaitLocalOnly) Controls whether the client only checks its local message buffer when using receiveNoWait calls, or will instead drain remaining credit from the remote peer synchronously to ensure there are really no messages available that have yet to arrive in the consumers local buffer.- Parameters:
receiveNoWaitLocalOnly- true if receiveNoWait calls should only check the local message buffer.
-
isPopulateJMSXUserID
public boolean isPopulateJMSXUserID() -
setPopulateJMSXUserID
public void setPopulateJMSXUserID(boolean populateJMSXUserID) Controls whether message sent from the Connection will have the JMSXUserID message property populated with the authenticated user ID of the Connection. When false all messages sent from the Connection will not carry any value in the JMSXUserID property regardless of it being manually set on the Message to prevent a client spoofing the JMSXUserID value.- Parameters:
populateJMSXUserID- true if message sent from this connection should have the JMSXUserID value populated.
-
setSslContext
Sets an SSLContext to use when creating an SSL/TLS secured connection with this factory. The URI must still be configured to indicate a secure connection should be created. Using this method overrides the effect of URI/System property configuration relating to the location/credentials/type of SSL key/trust stores and whether to trust all certificates or use a particular keyAlias.- Parameters:
sslContext- the sslContext to use, or null to respect the URI/System property configuration again.
-
isAwaitClientID
public boolean isAwaitClientID() -
setAwaitClientID
public void setAwaitClientID(boolean awaitClientID) Controls whether the client will wait for a ClientID value to be set or the Connection to be used before it will attempt to complete the AMQP connection Open process.By default a newly created Connection that does not have a ClientID configured in the URI will wait until a call to setClientID or some other interaction with the Connection API occurs before finishing the AMQP connection Open process with the remote peer. In some cases if this takes too long the remote can disconnect as a way of defending against denial of service attacks. If the user does not plan on setting a ClientID then this option allows for immediate AMQP connection Open completion and avoids the case where the remote peer might drop the Connection if it isn't used promptly.
This value defaults to true.
- Parameters:
awaitClientID- the whether to wait for the client ID to be set before activating the connection.
-
isUseDaemonThread
public boolean isUseDaemonThread() -
setUseDaemonThread
public void setUseDaemonThread(boolean useDaemonThread) Sets whether the Connection created will ensure that there is at least one non-daemon thread running at all times.- Parameters:
useDaemonThread- controls whether the Connection maintains a non-daemon thread.
-
isCloseLinksThatFailOnReconnect
public boolean isCloseLinksThatFailOnReconnect()- Returns:
- whether links that fail to be created during failover reconnect are closed or not.
-
setCloseLinksThatFailOnReconnect
public void setCloseLinksThatFailOnReconnect(boolean closeLinksThatFailOnReconnect) Controls how the client manages errors on recreation of a link (producer / consumer) during a failover reconnect attempt (defaults to false).When false the failure of a link recreation operation while reestablishing a failed connection results in the client failing that reconnect attempt and retrying the entire connection process again. This can be disabled by setting this option to true in which case the client will close the producer or consumer associated with the failed link create attempt and continue rebuilding the client resources for the newly reestablished connection. When failing a consumer link the client will trigger the
ExceptionListenerassigned to the Connection if the link that failed was a consumer and that consumer had an associated JMSMessageListener.- Parameters:
closeLinksThatFailOnReconnect- whether to close links that fail to establish on failover reconnect.
-
setExtension
public void setExtension(String extensionName, BiFunction<jakarta.jms.Connection, URI, Object> extension) Provides an entry point for extensions to be configured on thisConnectionFactory.If a previous extension with the same name is present it is replaced with the new value or cleared if the value is null.
- Parameters:
extensionName- The name of the extension point being added.extension- The Function that implements the extension.- See Also:
-
setTracing
Sets the type name for a tracing provider to use for the connection(s) created using the factory.- Parameters:
tracing- The tracing provider type name to set
-
getTracing
-
setTracer
Explicitly sets a tracer instance for use by the connection(s) created from the factory. Using this method overrides any implicit creation of a tracer due to use of either URI configuration option or thesetTracing(String)method. The provided tracer will have its close method called when a created connection/context is closed, so if a tracer is to be used across multiple such connections created by this factory then the close method should handle that appropriately, e.g no-op and have the application and/or underlying tracing implementation cleanup at shutdown. If no Connection/JMSContext object is returned from a creation attempt due to an exception being thrown, the tracer provided will not have its close method called and the application or underlying tracing implementation is responsible for any cleanup required.- Parameters:
tracer- The tracer to set
-
getTracer
Gets any tracer previously set explicitly on the connection factory usingsetTracer(JmsTracer). Does not return any tracer created implicitly due to use of either URI configuration option or thesetTracing(String)method.- Returns:
- the tracer previously set, or null if none was set.
-
getDefaultRemoteAddress
- Returns:
- the default remote address to connect to in the event that none was set.
-