Package org.apache.activemq.junit
Class EmbeddedActiveMQBroker
java.lang.Object
org.junit.rules.ExternalResource
org.apache.activemq.junit.EmbeddedActiveMQBroker
- All Implemented Interfaces:
TestRule
A JUnit Rule that embeds an ActiveMQ broker into a test.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionprotected voidafter()Stop the embedded ActiveMQ Brokerprotected voidbefore()Start the embedded ActiveMQ Brokerprotected voidCustomize the configuration of the embedded ActiveMQ brokerjakarta.jms.BytesMessageorg.apache.activemq.ActiveMQConnectionFactoryCreate an ActiveMQConnectionFactory for the embedded ActiveMQ Brokerjakarta.jms.MapMessagejakarta.jms.BytesMessagecreateMessage(byte[] body) jakarta.jms.BytesMessagecreateMessage(byte[] body, Map<String, Object> properties) jakarta.jms.ObjectMessagecreateMessage(Serializable body) jakarta.jms.ObjectMessagecreateMessage(Serializable body, Map<String, Object> properties) jakarta.jms.TextMessagecreateMessage(String body) jakarta.jms.TextMessagecreateMessage(String body, Map<String, Object> properties) jakarta.jms.MapMessagecreateMessage(Map<String, Object> body) jakarta.jms.MapMessagejakarta.jms.ObjectMessageCreate an PooledConnectionFactory for the embedded ActiveMQ Brokerjakarta.jms.StreamMessagejakarta.jms.TextMessagevoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidGet the name of the embedded ActiveMQ BrokerGet the BrokerService for the embedded ActiveMQ broker.getDestination(String destinationName) Get the ActiveMQ destinationlonggetMessageCount(String destinationName) Get the number of messages in a specific JMS Destination.getVmURI()Get the failover VM URI for the embedded ActiveMQ BrokergetVmURI(boolean failoverURI) Get the VM URI for the embedded ActiveMQ BrokergetVmURL()Get the failover VM URL for the embedded ActiveMQ BrokergetVmURL(boolean failoverURL) Get the VM URL for the embedded ActiveMQ Brokerbooleanbooleanbooleanbooleanbooleanbooleanjakarta.jms.BytesMessagepeekBytesMessage(String destinationName) jakarta.jms.MapMessagepeekMapMessage(String destinationName) jakarta.jms.MessagepeekMessage(String destinationName) jakarta.jms.ObjectMessagepeekObjectMessage(String destinationName) jakarta.jms.StreamMessagepeekStreamMessage(String destinationName) jakarta.jms.TextMessagepeekTextMessage(String destinationName) jakarta.jms.BytesMessagepushMessage(String destinationName, byte[] body) voidpushMessage(String destinationName, jakarta.jms.Message message) jakarta.jms.ObjectMessagepushMessage(String destinationName, Serializable body) jakarta.jms.TextMessagepushMessage(String destinationName, String body) jakarta.jms.MapMessagepushMessage(String destinationName, Map<String, Object> body) jakarta.jms.BytesMessagepushMessageWithProperties(String destinationName, byte[] body, Map<String, Object> properties) jakarta.jms.ObjectMessagepushMessageWithProperties(String destinationName, Serializable body, Map<String, Object> properties) jakarta.jms.TextMessagejakarta.jms.MapMessagepushMessageWithProperties(String destinationName, Map<String, Object> body, Map<String, Object> properties) voidsetBrokerName(String brokerName) static voidsetMessageProperties(jakarta.jms.Message message, Map<String, Object> properties) voidstart()Start the embedded ActiveMQ broker, blocking until the broker has successfully started.voidstop()Stop the embedded ActiveMQ broker, blocking until the broker has stopped.Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
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
Create an embedded ActiveMQ broker using a configuration URI -
EmbeddedActiveMQBroker
Create an embedded ActiveMQ broker using a configuration URI
-
-
Method Details
-
setMessageProperties
-
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
Start the embedded ActiveMQ Broker Invoked by JUnit to setup the resource- Overrides:
beforein classExternalResource- Throws:
Throwable
-
after
protected void after()Stop the embedded ActiveMQ Broker Invoked by JUnit to tear down the resource- Overrides:
afterin classExternalResource
-
createConnectionFactory
public org.apache.activemq.ActiveMQConnectionFactory createConnectionFactory()Create an ActiveMQConnectionFactory for the embedded ActiveMQ Broker- Returns:
- a new ActiveMQConnectionFactory
-
createPooledConnectionFactory
Create an PooledConnectionFactory for the embedded ActiveMQ Broker- Returns:
- a new PooledConnectionFactory
-
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
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
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
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
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
Get the name of the embedded ActiveMQ Broker- Returns:
- name of the embedded broker
-
setBrokerName
-
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
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
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
-
createMessage
-
createMessage
-
createMessage
-
createMessage
-
createMessage
-
createMessage
-
pushMessage
-
pushMessage
-
pushMessage
-
pushMessage
-
pushMessage
-
pushMessageWithProperties
-
pushMessageWithProperties
-
pushMessageWithProperties
-
pushMessageWithProperties
public jakarta.jms.ObjectMessage pushMessageWithProperties(String destinationName, Serializable body, Map<String, Object> properties) -
peekMessage
-
peekBytesMessage
-
peekTextMessage
-
peekMapMessage
-
peekObjectMessage
-
peekStreamMessage
-