Class EmbeddedActiveMQBroker

java.lang.Object
org.junit.rules.ExternalResource
org.apache.activemq.junit.EmbeddedActiveMQBroker
All Implemented Interfaces:
TestRule

public class EmbeddedActiveMQBroker extends ExternalResource
A JUnit Rule that embeds an ActiveMQ broker into a test.
  • Constructor Details

    • 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 Details

    • setMessageProperties

      public static void setMessageProperties(jakarta.jms.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 ExternalResource
      Throws:
      Throwable
    • after

      protected void after()
      Stop the embedded ActiveMQ Broker

      Invoked by JUnit to tear down the resource

      Overrides:
      after in class ExternalResource
    • createConnectionFactory

      public org.apache.activemq.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 jakarta.jms.BytesMessage createBytesMessage()
    • createTextMessage

      public jakarta.jms.TextMessage createTextMessage()
    • createMapMessage

      public jakarta.jms.MapMessage createMapMessage()
    • createObjectMessage

      public jakarta.jms.ObjectMessage createObjectMessage()
    • createStreamMessage

      public jakarta.jms.StreamMessage createStreamMessage()
    • createMessage

      public jakarta.jms.BytesMessage createMessage(byte[] body)
    • createMessage

      public jakarta.jms.TextMessage createMessage(String body)
    • createMessage

      public jakarta.jms.MapMessage createMessage(Map<String,Object> body)
    • createMessage

      public jakarta.jms.ObjectMessage createMessage(Serializable body)
    • createMessage

      public jakarta.jms.BytesMessage createMessage(byte[] body, Map<String,Object> properties)
    • createMessage

      public jakarta.jms.TextMessage createMessage(String body, Map<String,Object> properties)
    • createMessage

      public jakarta.jms.MapMessage createMessage(Map<String,Object> body, Map<String,Object> properties)
    • createMessage

      public jakarta.jms.ObjectMessage createMessage(Serializable body, Map<String,Object> properties)
    • pushMessage

      public void pushMessage(String destinationName, jakarta.jms.Message message)
    • pushMessage

      public jakarta.jms.BytesMessage pushMessage(String destinationName, byte[] body)
    • pushMessage

      public jakarta.jms.TextMessage pushMessage(String destinationName, String body)
    • pushMessage

      public jakarta.jms.MapMessage pushMessage(String destinationName, Map<String,Object> body)
    • pushMessage

      public jakarta.jms.ObjectMessage pushMessage(String destinationName, Serializable body)
    • pushMessageWithProperties

      public jakarta.jms.BytesMessage pushMessageWithProperties(String destinationName, byte[] body, Map<String,Object> properties)
    • pushMessageWithProperties

      public jakarta.jms.TextMessage pushMessageWithProperties(String destinationName, String body, Map<String,Object> properties)
    • pushMessageWithProperties

      public jakarta.jms.MapMessage pushMessageWithProperties(String destinationName, Map<String,Object> body, Map<String,Object> properties)
    • pushMessageWithProperties

      public jakarta.jms.ObjectMessage pushMessageWithProperties(String destinationName, Serializable body, Map<String,Object> properties)
    • peekMessage

      public jakarta.jms.Message peekMessage(String destinationName)
    • peekBytesMessage

      public jakarta.jms.BytesMessage peekBytesMessage(String destinationName)
    • peekTextMessage

      public jakarta.jms.TextMessage peekTextMessage(String destinationName)
    • peekMapMessage

      public jakarta.jms.MapMessage peekMapMessage(String destinationName)
    • peekObjectMessage

      public jakarta.jms.ObjectMessage peekObjectMessage(String destinationName)
    • peekStreamMessage

      public jakarta.jms.StreamMessage peekStreamMessage(String destinationName)