Package org.apache.activemq.junit
Class EmbeddedActiveMQBroker
- java.lang.Object
-
- org.junit.rules.ExternalResource
-
- org.apache.activemq.junit.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EmbeddedActiveMQBroker.EmbeddedActiveMQBrokerException
-
Constructor Summary
Constructors Constructor Description EmbeddedActiveMQBroker()
Create an embedded ActiveMQ broker using defaultsEmbeddedActiveMQBroker(String configurationURI)
Create an embedded ActiveMQ broker using a configuration URIEmbeddedActiveMQBroker(URI configurationURI)
Create an embedded ActiveMQ broker using a configuration URI
-
Method Summary
-
-
-
Constructor Detail
-
EmbeddedActiveMQBroker
public EmbeddedActiveMQBroker()
Create an embedded ActiveMQ broker using defaultsThe 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 brokerThis 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 classorg.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 classorg.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)
-
createMessage
public TextMessage createMessage(String body)
-
createMessage
public MapMessage createMessage(Map<String,Object> body)
-
createMessage
public ObjectMessage createMessage(Serializable body)
-
createMessage
public BytesMessage createMessage(byte[] body, Map<String,Object> properties)
-
createMessage
public TextMessage createMessage(String body, Map<String,Object> properties)
-
createMessage
public MapMessage createMessage(Map<String,Object> body, Map<String,Object> properties)
-
createMessage
public ObjectMessage createMessage(Serializable body, Map<String,Object> properties)
-
pushMessage
public BytesMessage pushMessage(String destinationName, byte[] body)
-
pushMessage
public TextMessage pushMessage(String destinationName, String body)
-
pushMessage
public MapMessage pushMessage(String destinationName, Map<String,Object> body)
-
pushMessage
public ObjectMessage pushMessage(String destinationName, Serializable body)
-
pushMessageWithProperties
public BytesMessage pushMessageWithProperties(String destinationName, byte[] body, Map<String,Object> properties)
-
pushMessageWithProperties
public TextMessage pushMessageWithProperties(String destinationName, String body, Map<String,Object> properties)
-
pushMessageWithProperties
public MapMessage pushMessageWithProperties(String destinationName, Map<String,Object> body, Map<String,Object> properties)
-
pushMessageWithProperties
public ObjectMessage pushMessageWithProperties(String destinationName, Serializable body, Map<String,Object> properties)
-
peekBytesMessage
public BytesMessage peekBytesMessage(String destinationName)
-
peekTextMessage
public TextMessage peekTextMessage(String destinationName)
-
peekMapMessage
public MapMessage peekMapMessage(String destinationName)
-
peekObjectMessage
public ObjectMessage peekObjectMessage(String destinationName)
-
peekStreamMessage
public StreamMessage peekStreamMessage(String destinationName)
-
-