Class ActiveMQConnectionFactory

java.lang.Object
org.apache.activemq.jndi.JNDIBaseStorable
org.apache.activemq.ActiveMQConnectionFactory
All Implemented Interfaces:
jakarta.jms.ConnectionFactory, jakarta.jms.QueueConnectionFactory, jakarta.jms.TopicConnectionFactory, Externalizable, Serializable, Cloneable, Referenceable, JNDIStorableInterface, StatsCapable
Direct Known Subclasses:
ActiveMQSslConnectionFactory, ActiveMQXAConnectionFactory

public class ActiveMQConnectionFactory extends JNDIBaseStorable implements jakarta.jms.ConnectionFactory, jakarta.jms.QueueConnectionFactory, jakarta.jms.TopicConnectionFactory, StatsCapable, Cloneable
A ConnectionFactory is an an Administered object, and is used for creating Connections.

This class also implements QueueConnectionFactory and TopicConnectionFactory. You can use this connection to create both QueueConnections and TopicConnections.

See Also:
  • Field Details

    • DEFAULT_BROKER_BIND_URL

      public static final String DEFAULT_BROKER_BIND_URL
    • DEFAULT_BROKER_URL

      public static final String DEFAULT_BROKER_URL
    • DEFAULT_USER

      public static final String DEFAULT_USER
    • DEFAULT_PASSWORD

      public static final String DEFAULT_PASSWORD
    • DEFAULT_PRODUCER_WINDOW_SIZE

      public static final int DEFAULT_PRODUCER_WINDOW_SIZE
      See Also:
    • brokerURL

      protected URI brokerURL
    • userName

      protected String userName
    • password

      protected String password
    • clientID

      protected String clientID
    • dispatchAsync

      protected boolean dispatchAsync
    • alwaysSessionAsync

      protected boolean alwaysSessionAsync
    • xaAckMode

      protected int xaAckMode
  • Constructor Details

    • ActiveMQConnectionFactory

      public ActiveMQConnectionFactory()
    • ActiveMQConnectionFactory

      public ActiveMQConnectionFactory(String brokerURL)
    • ActiveMQConnectionFactory

      public ActiveMQConnectionFactory(URI brokerURL)
    • ActiveMQConnectionFactory

      public ActiveMQConnectionFactory(String userName, String password, URI brokerURL)
    • ActiveMQConnectionFactory

      public ActiveMQConnectionFactory(String userName, String password, String brokerURL)
  • Method Details

    • copy

      Returns a copy of the given connection factory
    • createConnection

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

      public jakarta.jms.Connection createConnection(String userName, String password) throws jakarta.jms.JMSException
      Specified by:
      createConnection in interface jakarta.jms.ConnectionFactory
      Returns:
      Returns the Connection.
      Throws:
      jakarta.jms.JMSException
    • createQueueConnection

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

      public jakarta.jms.QueueConnection createQueueConnection(String userName, String password) throws jakarta.jms.JMSException
      Specified by:
      createQueueConnection in interface jakarta.jms.QueueConnectionFactory
      Returns:
      Returns the QueueConnection.
      Throws:
      jakarta.jms.JMSException
    • createTopicConnection

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

      public jakarta.jms.TopicConnection createTopicConnection(String userName, String password) throws jakarta.jms.JMSException
      Specified by:
      createTopicConnection in interface jakarta.jms.TopicConnectionFactory
      Returns:
      Returns the TopicConnection.
      Throws:
      jakarta.jms.JMSException
    • createContext

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

      public jakarta.jms.JMSContext createContext(String userName, String password)
      Specified by:
      createContext in interface jakarta.jms.ConnectionFactory
      Returns:
      Returns the JMSContext.
    • createContext

      public jakarta.jms.JMSContext createContext(String userName, String password, int sessionMode)
      Specified by:
      createContext in interface jakarta.jms.ConnectionFactory
      Returns:
      Returns the JMSContext.
    • createContext

      public jakarta.jms.JMSContext createContext(int sessionMode)
      Specified by:
      createContext in interface jakarta.jms.ConnectionFactory
      Returns:
      Returns the JMSContext.
    • getStats

      public StatsImpl getStats()
      Specified by:
      getStats in interface StatsCapable
      Returns:
      the StatsImpl associated with this ConnectionFactory.
    • createActiveMQConnection

      protected ActiveMQConnection createActiveMQConnection() throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
    • createTransport

      protected Transport createTransport() throws jakarta.jms.JMSException
      Creates a Transport based on this object's connection settings. Separated from createActiveMQConnection to allow for subclasses to override.
      Returns:
      The newly created Transport.
      Throws:
      jakarta.jms.JMSException - If unable to create trasnport.
    • createActiveMQConnection

      protected ActiveMQConnection createActiveMQConnection(String userName, String password) throws jakarta.jms.JMSException
      Returns:
      Returns the Connection.
      Throws:
      jakarta.jms.JMSException
    • createActiveMQConnection

      protected ActiveMQConnection createActiveMQConnection(Transport transport, JMSStatsImpl stats) throws Exception
      Throws:
      Exception
    • configureConnection

      protected void configureConnection(ActiveMQConnection connection) throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
    • getBrokerURL

      public String getBrokerURL()
    • setBrokerURL

      public void setBrokerURL(String brokerURL)
      Sets the connection URL used to connect to the ActiveMQ broker.
    • getClientID

      public String getClientID()
    • setClientID

      public void setClientID(String clientID)
      Sets the JMS clientID to use for the created connection. Note that this can only be used by one connection at once so generally its a better idea to set the clientID on a Connection
    • isCopyMessageOnSend

      public boolean isCopyMessageOnSend()
    • setCopyMessageOnSend

      public void setCopyMessageOnSend(boolean copyMessageOnSend)
      Should a JMS message be copied to a new JMS Message object as part of the send() method in JMS. This is enabled by default to be compliant with the JMS specification. You can disable it if you do not mutate JMS messages after they are sent for a performance boost
    • isDisableTimeStampsByDefault

      public boolean isDisableTimeStampsByDefault()
    • setDisableTimeStampsByDefault

      public void setDisableTimeStampsByDefault(boolean disableTimeStampsByDefault)
      Sets whether or not timestamps on messages should be disabled or not. If you disable them it adds a small performance boost.
    • isOptimizedMessageDispatch

      public boolean isOptimizedMessageDispatch()
    • setOptimizedMessageDispatch

      public void setOptimizedMessageDispatch(boolean optimizedMessageDispatch)
      If this flag is set then an larger prefetch limit is used - only applicable for durable topic subscribers.
    • getPassword

      public String getPassword()
    • setPassword

      public void setPassword(String password)
      Sets the JMS password used for connections created from this factory
    • getPrefetchPolicy

      public ActiveMQPrefetchPolicy getPrefetchPolicy()
    • setPrefetchPolicy

      public void setPrefetchPolicy(ActiveMQPrefetchPolicy prefetchPolicy)
      Sets the prefetch policy for consumers created by this connection.
    • isUseAsyncSend

      public boolean isUseAsyncSend()
    • getBlobTransferPolicy

      public BlobTransferPolicy getBlobTransferPolicy()
    • setBlobTransferPolicy

      public void setBlobTransferPolicy(BlobTransferPolicy blobTransferPolicy)
      Sets the policy used to describe how out-of-band BLOBs (Binary Large OBjects) are transferred from producers to brokers to consumers
    • setUseAsyncSend

      public void setUseAsyncSend(boolean useAsyncSend)
      Forces the use of Async Sends which adds a massive performance boost; but means that the send() method will return immediately whether the message has been sent or not which could lead to message loss.
    • isWatchTopicAdvisories

      public boolean isWatchTopicAdvisories()
    • setWatchTopicAdvisories

      public void setWatchTopicAdvisories(boolean watchTopicAdvisories)
    • isAlwaysSyncSend

      public boolean isAlwaysSyncSend()
      Returns:
      true if always sync send messages
    • setAlwaysSyncSend

      public void setAlwaysSyncSend(boolean alwaysSyncSend)
      Set true if always require messages to be sync sent
      Parameters:
      alwaysSyncSend -
    • getUserName

      public String getUserName()
    • setUserName

      public void setUserName(String userName)
      Sets the JMS userName used by connections created by this factory
    • isUseRetroactiveConsumer

      public boolean isUseRetroactiveConsumer()
    • setUseRetroactiveConsumer

      public void setUseRetroactiveConsumer(boolean useRetroactiveConsumer)
      Sets whether or not retroactive consumers are enabled. Retroactive consumers allow non-durable topic subscribers to receive old messages that were published before the non-durable subscriber started.
    • isExclusiveConsumer

      public boolean isExclusiveConsumer()
    • setExclusiveConsumer

      public void setExclusiveConsumer(boolean exclusiveConsumer)
      Enables or disables whether or not queue consumers should be exclusive or not for example to preserve ordering when not using Message Groups
      Parameters:
      exclusiveConsumer -
    • getRedeliveryPolicy

      public RedeliveryPolicy getRedeliveryPolicy()
    • setRedeliveryPolicy

      public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy)
      Sets the global default redelivery policy to be used when a message is delivered but the session is rolled back
    • getRedeliveryPolicyMap

      public RedeliveryPolicyMap getRedeliveryPolicyMap()
    • setRedeliveryPolicyMap

      public void setRedeliveryPolicyMap(RedeliveryPolicyMap redeliveryPolicyMap)
      Sets the global redelivery policy mapping to be used when a message is delivered but the session is rolled back
    • getTransformer

      public MessageTransformer getTransformer()
    • getSendTimeout

      public int getSendTimeout()
      Returns:
      the sendTimeout (in milliseconds)
    • setSendTimeout

      public void setSendTimeout(int sendTimeout)
      Parameters:
      sendTimeout - the sendTimeout to set (in milliseconds)
    • isSendAcksAsync

      public boolean isSendAcksAsync()
      Returns:
      the sendAcksAsync
    • setSendAcksAsync

      public void setSendAcksAsync(boolean sendAcksAsync)
      Parameters:
      sendAcksAsync - the sendAcksAsync to set
    • isMessagePrioritySupported

      public boolean isMessagePrioritySupported()
      Returns:
      the messagePrioritySupported
    • setMessagePrioritySupported

      public void setMessagePrioritySupported(boolean messagePrioritySupported)
      Parameters:
      messagePrioritySupported - the messagePrioritySupported to set
    • setTransformer

      public void setTransformer(MessageTransformer transformer)
      Sets the transformer used to transform messages before they are sent on to the JMS bus or when they are received from the bus but before they are delivered to the JMS client
    • buildFromProperties

      public void buildFromProperties(Properties properties)
      Description copied from class: JNDIBaseStorable
      Set the properties that will represent the instance in JNDI
      Specified by:
      buildFromProperties in class JNDIBaseStorable
    • buildFromMap

      public boolean buildFromMap(Map<String,Object> properties)
    • populateProperties

      public void populateProperties(Properties props)
      Description copied from class: JNDIBaseStorable
      Initialize the instance from properties stored in JNDI
      Specified by:
      populateProperties in class JNDIBaseStorable
    • isUseCompression

      public boolean isUseCompression()
    • setUseCompression

      public void setUseCompression(boolean useCompression)
      Enables the use of compression of the message bodies
    • isObjectMessageSerializationDefered

      public boolean isObjectMessageSerializationDefered()
    • setObjectMessageSerializationDefered

      public void setObjectMessageSerializationDefered(boolean objectMessageSerializationDefered)
      When an object is set on an ObjectMessage, the JMS spec requires the object to be serialized by that set method. Enabling this flag causes the object to not get serialized. The object may subsequently get serialized if the message needs to be sent over a socket or stored to disk.
    • isDispatchAsync

      public boolean isDispatchAsync()
    • setDispatchAsync

      public void setDispatchAsync(boolean asyncDispatch)
      Enables or disables the default setting of whether or not consumers have their messages dispatched synchronously or asynchronously by the broker. For non-durable topics for example we typically dispatch synchronously by default to minimize context switches which boost performance. However sometimes its better to go slower to ensure that a single blocked consumer socket does not block delivery to other consumers.
      Parameters:
      asyncDispatch - If true then consumers created on this connection will default to having their messages dispatched asynchronously. The default value is true.
    • getCloseTimeout

      public int getCloseTimeout()
      Returns:
      Returns the closeTimeout.
    • setCloseTimeout

      public void setCloseTimeout(int closeTimeout)
      Sets the timeout before a close is considered complete. Normally a close() on a connection waits for confirmation from the broker; this allows that operation to timeout to save the client hanging if there is no broker
    • isAlwaysSessionAsync

      public boolean isAlwaysSessionAsync()
      Returns:
      Returns the alwaysSessionAsync.
    • setAlwaysSessionAsync

      public void setAlwaysSessionAsync(boolean alwaysSessionAsync)
      If this flag is not set then a separate thread is not used for dispatching messages for each Session in the Connection. However, a separate thread is always used if there is more than one session, or the session isn't in auto acknowledge or duplicates ok mode. By default this value is set to true and session dispatch happens asynchronously.
    • isOptimizeAcknowledge

      public boolean isOptimizeAcknowledge()
      Returns:
      Returns the optimizeAcknowledge.
    • setOptimizeAcknowledge

      public void setOptimizeAcknowledge(boolean optimizeAcknowledge)
      Parameters:
      optimizeAcknowledge - The optimizeAcknowledge to set.
    • setOptimizeAcknowledgeTimeOut

      public void setOptimizeAcknowledgeTimeOut(long optimizeAcknowledgeTimeOut)
      The max time in milliseconds between optimized ack batches
      Parameters:
      optimizeAcknowledgeTimeOut -
    • getOptimizeAcknowledgeTimeOut

      public long getOptimizeAcknowledgeTimeOut()
    • isNestedMapAndListEnabled

      public boolean isNestedMapAndListEnabled()
    • setNestedMapAndListEnabled

      public void setNestedMapAndListEnabled(boolean structuredMapsEnabled)
      Enables/disables whether or not Message properties and MapMessage entries support Nested Structures of Map and List objects
    • getClientIDPrefix

      public String getClientIDPrefix()
    • setClientIDPrefix

      public void setClientIDPrefix(String clientIDPrefix)
      Sets the prefix used by autogenerated JMS Client ID values which are used if the JMS client does not explicitly specify on.
      Parameters:
      clientIDPrefix -
    • getClientIdGenerator

      protected IdGenerator getClientIdGenerator()
    • setClientIdGenerator

      protected void setClientIdGenerator(IdGenerator clientIdGenerator)
    • setConnectionIDPrefix

      public void setConnectionIDPrefix(String connectionIDPrefix)
      Sets the prefix used by connection id generator
      Parameters:
      connectionIDPrefix -
    • getConnectionIdGenerator

      protected IdGenerator getConnectionIdGenerator()
    • setConnectionIdGenerator

      protected void setConnectionIdGenerator(IdGenerator connectionIdGenerator)
    • isStatsEnabled

      public boolean isStatsEnabled()
      Returns:
      the statsEnabled
    • setStatsEnabled

      public void setStatsEnabled(boolean statsEnabled)
      Parameters:
      statsEnabled - the statsEnabled to set
    • getProducerWindowSize

      public int getProducerWindowSize()
    • setProducerWindowSize

      public void setProducerWindowSize(int producerWindowSize)
    • getWarnAboutUnstartedConnectionTimeout

      public long getWarnAboutUnstartedConnectionTimeout()
    • setWarnAboutUnstartedConnectionTimeout

      public void setWarnAboutUnstartedConnectionTimeout(long warnAboutUnstartedConnectionTimeout)
      Enables the timeout from a connection creation to when a warning is generated if the connection is not properly started via Connection.start() and a message is received by a consumer. It is a very common gotcha to forget to start the connection so this option makes the default case to create a warning if the user forgets. To disable the warning just set the value to < 0 (say -1).
    • getTransportListener

      public TransportListener getTransportListener()
    • setTransportListener

      public void setTransportListener(TransportListener transportListener)
      Allows a listener to be configured on the ConnectionFactory so that when this factory is used with frameworks which don't expose the Connection such as Spring JmsTemplate, you can still register a transport listener.
      Parameters:
      transportListener - sets the listener to be registered on all connections created by this factory
    • getExceptionListener

      public jakarta.jms.ExceptionListener getExceptionListener()
    • setExceptionListener

      public void setExceptionListener(jakarta.jms.ExceptionListener exceptionListener)
      Allows an ExceptionListener to be configured on the ConnectionFactory so that when this factory is used by frameworks which don't expose the Connection such as Spring JmsTemplate, you can register an exception listener.

      Note: access to this exceptionLinstener will not be serialized if it is associated with more than on connection (as it will be if more than one connection is subsequently created by this connection factory)

      Parameters:
      exceptionListener - sets the exception listener to be registered on all connections created by this factory
    • getAuditDepth

      public int getAuditDepth()
    • setAuditDepth

      public void setAuditDepth(int auditDepth)
    • getAuditMaximumProducerNumber

      public int getAuditMaximumProducerNumber()
    • setAuditMaximumProducerNumber

      public void setAuditMaximumProducerNumber(int auditMaximumProducerNumber)
    • setUseDedicatedTaskRunner

      public void setUseDedicatedTaskRunner(boolean useDedicatedTaskRunner)
    • isUseDedicatedTaskRunner

      public boolean isUseDedicatedTaskRunner()
    • setConsumerFailoverRedeliveryWaitPeriod

      public void setConsumerFailoverRedeliveryWaitPeriod(long consumerFailoverRedeliveryWaitPeriod)
    • getConsumerFailoverRedeliveryWaitPeriod

      public long getConsumerFailoverRedeliveryWaitPeriod()
    • getClientInternalExceptionListener

      public ClientInternalExceptionListener getClientInternalExceptionListener()
    • setClientInternalExceptionListener

      public void setClientInternalExceptionListener(ClientInternalExceptionListener clientInternalExceptionListener)
      Allows an ClientInternalExceptionListener to be configured on the ConnectionFactory so that when this factory is used by frameworks which don't expose the Connection such as Spring JmsTemplate, you can register an exception listener.

      Note: access to this clientInternalExceptionListener will not be serialized if it is associated with more than on connection (as it will be if more than one connection is subsequently created by this connection factory)

      Parameters:
      clientInternalExceptionListener - sets the exception listener to be registered on all connections created by this factory
    • isCheckForDuplicates

      public boolean isCheckForDuplicates()
      Returns:
      the checkForDuplicates
    • setCheckForDuplicates

      public void setCheckForDuplicates(boolean checkForDuplicates)
      Parameters:
      checkForDuplicates - the checkForDuplicates to set
    • isTransactedIndividualAck

      public boolean isTransactedIndividualAck()
    • setTransactedIndividualAck

      public void setTransactedIndividualAck(boolean transactedIndividualAck)
      when true, submit individual transacted acks immediately rather than with transaction completion. This allows the acks to represent delivery status which can be persisted on rollback Used in conjunction with org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter#setRewriteOnRedelivery(boolean) true
    • isNonBlockingRedelivery

      public boolean isNonBlockingRedelivery()
    • setNonBlockingRedelivery

      public void setNonBlockingRedelivery(boolean nonBlockingRedelivery)
      When true a MessageConsumer will not stop Message delivery before re-delivering Messages from a rolled back transaction. This implies that message order will not be preserved and also will result in the TransactedIndividualAck option to be enabled.
    • getMaxThreadPoolSize

      public int getMaxThreadPoolSize()
    • setMaxThreadPoolSize

      public void setMaxThreadPoolSize(int maxThreadPoolSize)
    • getSessionTaskRunner

      public TaskRunnerFactory getSessionTaskRunner()
    • setSessionTaskRunner

      public void setSessionTaskRunner(TaskRunnerFactory sessionTaskRunner)
    • getRejectedTaskHandler

      public RejectedExecutionHandler getRejectedTaskHandler()
    • setRejectedTaskHandler

      public void setRejectedTaskHandler(RejectedExecutionHandler rejectedTaskHandler)
    • getOptimizedAckScheduledAckInterval

      public long getOptimizedAckScheduledAckInterval()
      Gets the configured time interval that is used to force all MessageConsumers that have optimizedAcknowledge enabled to send an ack for any outstanding Message Acks. By default this value is set to zero meaning that the consumers will not do any background Message acknowledgment.
      Returns:
      the scheduledOptimizedAckInterval
    • setOptimizedAckScheduledAckInterval

      public void setOptimizedAckScheduledAckInterval(long optimizedAckScheduledAckInterval)
      Sets the amount of time between scheduled sends of any outstanding Message Acks for consumers that have been configured with optimizeAcknowledge enabled.
      Parameters:
      optimizedAckScheduledAckInterval - the scheduledOptimizedAckInterval to set
    • isRmIdFromConnectionId

      public boolean isRmIdFromConnectionId()
    • setRmIdFromConnectionId

      public void setRmIdFromConnectionId(boolean rmIdFromConnectionId)
      uses the connection id as the resource identity for XAResource.isSameRM ensuring join will only occur on a single connection
    • isConsumerExpiryCheckEnabled

      public boolean isConsumerExpiryCheckEnabled()
      Returns:
      true if MessageConsumer instance will check for expired messages before dispatch.
    • setConsumerExpiryCheckEnabled

      public void setConsumerExpiryCheckEnabled(boolean consumerExpiryCheckEnabled)
      Controls whether message expiration checking is done in each MessageConsumer prior to dispatching a message. Disabling this check can lead to consumption of expired messages.
      Parameters:
      consumerExpiryCheckEnabled - controls whether expiration checking is done prior to dispatch.
    • getTrustedPackages

      public List<String> getTrustedPackages()
    • setTrustedPackages

      public void setTrustedPackages(List<String> trustedPackages)
    • isTrustAllPackages

      public boolean isTrustAllPackages()
    • setTrustAllPackages

      public void setTrustAllPackages(boolean trustAllPackages)
    • getConnectResponseTimeout

      public int getConnectResponseTimeout()
    • setConnectResponseTimeout

      public void setConnectResponseTimeout(int connectResponseTimeout)