Class EmbeddedActiveMQBroker

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class EmbeddedActiveMQBroker
    extends org.junit.rules.ExternalResource
    A JUnit Rule that embeds an ActiveMQ broker into a test.
    • Constructor Detail

      • EmbeddedActiveMQBroker

        public EmbeddedActiveMQBroker()
        Create an embedded ActiveMQ broker using defaults

        The defaults are: - the broker name is 'embedded-broker' - JMX is enable but no management connector is created. - Persistence is disabled

      • EmbeddedActiveMQBroker

        public EmbeddedActiveMQBroker​(String configurationURI)
        Create an embedded ActiveMQ broker using a configuration URI
      • EmbeddedActiveMQBroker

        public EmbeddedActiveMQBroker​(URI configurationURI)
        Create an embedded ActiveMQ broker using a configuration URI
    • Method Detail

      • setMessageProperties

        public static void setMessageProperties​(Message message,
                                                Map<String,​Object> properties)
      • configure

        protected void configure()
        Customize the configuration of the embedded ActiveMQ broker

        This method is called before the embedded ActiveMQ broker is started, and can be overridden to this method to customize the broker configuration.

      • start

        public void start()
        Start the embedded ActiveMQ broker, blocking until the broker has successfully started.

        The broker will normally be started by JUnit using the before() method. This method allows the broker to be started manually to support advanced testing scenarios.

      • stop

        public void stop()
        Stop the embedded ActiveMQ broker, blocking until the broker has stopped.

        The broker will normally be stopped by JUnit using the after() method. This method allows the broker to be stopped manually to support advanced testing scenarios.

      • before

        protected void before()
                       throws Throwable
        Start the embedded ActiveMQ Broker

        Invoked by JUnit to setup the resource

        Overrides:
        before in class org.junit.rules.ExternalResource
        Throws:
        Throwable
      • after

        protected void after()
        Stop the embedded ActiveMQ Broker

        Invoked by JUnit to tear down the resource

        Overrides:
        after in class org.junit.rules.ExternalResource
      • createConnectionFactory

        public ActiveMQConnectionFactory createConnectionFactory()
        Create an ActiveMQConnectionFactory for the embedded ActiveMQ Broker
        Returns:
        a new ActiveMQConnectionFactory
      • createPooledConnectionFactory

        public PooledConnectionFactory createPooledConnectionFactory()
        Create an PooledConnectionFactory for the embedded ActiveMQ Broker
        Returns:
        a new PooledConnectionFactory
      • getBrokerService

        public BrokerService getBrokerService()
        Get the BrokerService for the embedded ActiveMQ broker.

        This may be required for advanced configuration of the BrokerService.

        Returns:
        the embedded ActiveMQ broker
      • getVmURL

        public String getVmURL()
        Get the failover VM URL for the embedded ActiveMQ Broker

        NOTE: The create=false option is appended to the URL to avoid the automatic creation of brokers and the resulting duplicate broker errors

        Returns:
        the VM URL for the embedded broker
      • getVmURL

        public String getVmURL​(boolean failoverURL)
        Get the VM URL for the embedded ActiveMQ Broker

        NOTE: The create=false option is appended to the URL to avoid the automatic creation of brokers and the resulting duplicate broker errors

        Parameters:
        failoverURL - if true a failover URL will be returned
        Returns:
        the VM URL for the embedded broker
      • getVmURI

        public URI getVmURI()
        Get the failover VM URI for the embedded ActiveMQ Broker

        NOTE: The create=false option is appended to the URI to avoid the automatic creation of brokers and the resulting duplicate broker errors

        Returns:
        the VM URI for the embedded broker
      • getVmURI

        public URI getVmURI​(boolean failoverURI)
        Get the VM URI for the embedded ActiveMQ Broker

        NOTE: The create=false option is appended to the URI to avoid the automatic creation of brokers and the resulting duplicate broker errors

        Parameters:
        failoverURI - if true a failover URI will be returned
        Returns:
        the VM URI for the embedded broker
      • getBrokerName

        public String getBrokerName()
        Get the name of the embedded ActiveMQ Broker
        Returns:
        name of the embedded broker
      • setBrokerName

        public void setBrokerName​(String brokerName)
      • isStatisticsPluginEnabled

        public boolean isStatisticsPluginEnabled()
      • enableStatisticsPlugin

        public void enableStatisticsPlugin()
      • disableStatisticsPlugin

        public void disableStatisticsPlugin()
      • isAdvisoryForDeliveryEnabled

        public boolean isAdvisoryForDeliveryEnabled()
      • enableAdvisoryForDelivery

        public void enableAdvisoryForDelivery()
      • disableAdvisoryForDelivery

        public void disableAdvisoryForDelivery()
      • isAdvisoryForConsumedEnabled

        public boolean isAdvisoryForConsumedEnabled()
      • enableAdvisoryForConsumed

        public void enableAdvisoryForConsumed()
      • disableAdvisoryForConsumed

        public void disableAdvisoryForConsumed()
      • isAdvisoryForDiscardingMessagesEnabled

        public boolean isAdvisoryForDiscardingMessagesEnabled()
      • enableAdvisoryForDiscardingMessages

        public void enableAdvisoryForDiscardingMessages()
      • disableAdvisoryForDiscardingMessages

        public void disableAdvisoryForDiscardingMessages()
      • isAdvisoryForFastProducersEnabled

        public boolean isAdvisoryForFastProducersEnabled()
      • enableAdvisoryForFastProducers

        public void enableAdvisoryForFastProducers()
      • disableAdvisoryForFastProducers

        public void disableAdvisoryForFastProducers()
      • isAdvisoryForSlowConsumersEnabled

        public boolean isAdvisoryForSlowConsumersEnabled()
      • enableAdvisoryForSlowConsumers

        public void enableAdvisoryForSlowConsumers()
      • disableAdvisoryForSlowConsumers

        public void disableAdvisoryForSlowConsumers()
      • getMessageCount

        public long getMessageCount​(String destinationName)
        Get the number of messages in a specific JMS Destination.

        The full name of the JMS destination including the prefix should be provided - i.e. queue://myQueue or topic://myTopic. If the destination type prefix is not included in the destination name, a prefix of "queue://" is assumed.

        Parameters:
        destinationName - the full name of the JMS Destination
        Returns:
        the number of messages in the JMS Destination
      • getDestination

        public Destination getDestination​(String destinationName)
        Get the ActiveMQ destination

        The full name of the JMS destination including the prefix should be provided - i.e. queue://myQueue or topic://myTopic. If the destination type prefix is not included in the destination name, a prefix of "queue://" is assumed.

        Parameters:
        destinationName - the full name of the JMS Destination
        Returns:
        the ActiveMQ destination, null if not found
      • createBytesMessage

        public BytesMessage createBytesMessage()
      • createTextMessage

        public TextMessage createTextMessage()
      • createMapMessage

        public MapMessage createMapMessage()
      • createObjectMessage

        public ObjectMessage createObjectMessage()
      • createStreamMessage

        public StreamMessage createStreamMessage()
      • createMessage

        public BytesMessage createMessage​(byte[] body)
      • pushMessage

        public void pushMessage​(String destinationName,
                                Message message)
      • peekMessage

        public Message peekMessage​(String destinationName)