Package io.mats3.test.broker
Interface MatsTestBroker
- All Known Implementing Classes:
MatsTestBroker.MatsTestBroker_ActiveMq
,MatsTestBroker.MatsTestBroker_Artemis
,MatsTestBroker.MatsTestBroker_InVmActiveMq
public interface MatsTestBroker
A special utility class utilized in tests and Mats test infrastructure providing a ConnectionFactory for the test
(Jms)MatsFactory - and if relevant also fires up an embedded ("in-VM") ActiveMQ (default) or Artemis message broker.
If the system property "
mats.test.broker
" is set, it directs which type of broker
should be connected to, and possibly instantiate embedded.
If the system property "mats.test.brokerurl
" is set, it both defines whether the
embedded message broker will be created and which URL the created ConnectionFactory should use.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Feature flags for the methodnewActiveMqBroker(ActiveMq...)
- which you probably shouldn't do unless you are experimenting with the "mats-examples".static class
Either creates an in-vm ActiveMQ, or an ActiveMQ ConnectionFactory to an external URL, based on system properties.static class
Creates a connection to an Artemis broker.static class
Creates an in-vm ActiveMQ no matter what the properties says. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Which Broker client to use (which JMSConnectionFactory
implementation): activemq (default), artemis or rabbitmq - or if a class-name like String, assumes that it is an implementation of the present interface (MatsTestBroker
) and instantiates that.static final String
DEFAULT: Use ActiveMQ as broker.static final String
Use Artemis (Apache ActiveMQ Artemis) as broker - this was formerly JBoss HornetQ.static final String
Use RabbitMQ as broker.static final String
System property ("-D" jvm argument) that if set to something else thanSYSPROP_MATS_TEST_BROKERURL_VALUE_IN_VM
, will Not start an embedded ("in-VM") ActiveMQ instance. Make the ConnectionFactory use the property's value as brokerURL - with the special case that if the value is "LOCALHOST
", it means default localhost connection string foractive broker
, e.g.static final String
DEFAULT: If the value ofSYSPROP_MATS_TEST_BROKERURL
is this value OR not set (i.e.static final String
If the value ofSYSPROP_MATS_TEST_BROKERURL
is this value, it means default localhost connection string foractive broker
, e.g. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Stops the created in-vm broker, if it was created (readSYSPROP_MATS_TEST_BROKERURL
).static MatsTestBroker
create()
static MatsTestBroker
This is a special factory method, which creates a unique (randomly named) in-vm ActiveMQ instance, no matter what the system properties says.javax.jms.ConnectionFactory
static org.apache.activemq.broker.BrokerService
newActiveMqBroker
(MatsTestBroker.ActiveMq... features) Note: This is most probably not what you want to use in a testing scenario - for this you want to use the methodMatsTestBroker
class directly, using itscreate()
method.
-
Field Details
-
SYSPROP_MATS_TEST_BROKER
Which Broker client to use (which JMSConnectionFactory
implementation): activemq (default), artemis or rabbitmq - or if a class-name like String, assumes that it is an implementation of the present interface (MatsTestBroker
) and instantiates that.- See Also:
-
SYSPROP_MATS_TEST_BROKER_VALUE_ACTIVEMQ
DEFAULT: Use ActiveMQ as broker.- See Also:
-
SYSPROP_MATS_TEST_BROKER_VALUE_ARTEMIS
Use Artemis (Apache ActiveMQ Artemis) as broker - this was formerly JBoss HornetQ.- See Also:
-
SYSPROP_MATS_TEST_BROKER_VALUE_RABBITMQ
Use RabbitMQ as broker. This cannot be used in embedded mode, since RabbitMQ is written in Erlang.- See Also:
-
SYSPROP_MATS_TEST_BROKERURL
System property ("-D" jvm argument) that if set to something else thanSYSPROP_MATS_TEST_BROKERURL_VALUE_IN_VM
, will- Not start an embedded ("in-VM") ActiveMQ instance.
- Make the ConnectionFactory use the property's value as brokerURL - with the special case that if the value is
"
LOCALHOST
", it means default localhost connection string foractive broker
, e.g. for ActiveMQ:"tcp://localhost:61616"
Value is
"mats.test.brokerurl"
- See Also:
-
SYSPROP_MATS_TEST_BROKERURL_VALUE_IN_VM
DEFAULT: If the value ofSYSPROP_MATS_TEST_BROKERURL
is this value OR not set (i.e. this is the default), the ConnectionFactory will use an in-VM connection method for theactive broker
, e.g. for ActiveMQ:"vm://{brokername}"
. (Note that RabbitMQ does not support in-VM, since it's written in Erlang).Value is
"in-vm"
- See Also:
-
SYSPROP_MATS_TEST_BROKERURL_VALUE_LOCALHOST
If the value ofSYSPROP_MATS_TEST_BROKERURL
is this value, it means default localhost connection string foractive broker
, e.g. for ActiveMQ:"tcp://localhost:61616"
.Value is
"localhost"
- See Also:
-
-
Method Details
-
create
- Returns:
- a MatsTestBroker implementation respecting the system properties set (defaults are probably good!).
-
createUniqueInVmActiveMq
This is a special factory method, which creates a unique (randomly named) in-vm ActiveMQ instance, no matter what the system properties says. This is only relevant in very specific test scenarios where you specifically want more than a single broker, due to wanting multiple distinct MatsFactories utilizing these distinct brokers, i.e. multiple separate "Mats fabrics". It is used by the Mats test suites to check that the SpringConfig handles multiple MatsFactories each employing a different broker with separate JMS ConnectionFactories (which is relevant if you have multiple brokers in your environment to e.g. subdivide the traffic, but some services are relevant for more than one of those subdivisions, and thus those services want "one leg in each broker").- Returns:
- an in-vm ActiveMQ backed MatsTestBroker, no matter what the system properties says.
-
getConnectionFactory
javax.jms.ConnectionFactory getConnectionFactory()- Returns:
- the ConnectionFactory connecting to the broker.
-
close
void close()Stops the created in-vm broker, if it was created (readSYSPROP_MATS_TEST_BROKERURL
). Called "close()" to hook into the default Spring lifecycle if it is instantiated as a Spring Bean. -
newActiveMqBroker
static org.apache.activemq.broker.BrokerService newActiveMqBroker(MatsTestBroker.ActiveMq... features) Note: This is most probably not what you want to use in a testing scenario - for this you want to use the methodMatsTestBroker
class directly, using itscreate()
method. This method is publicly available for examples and experiments, and provide a way to create an ActiveMQ broker with some Mats optimizations, with a single method call.- Returns:
- a new ActiveMQ Broker instance.
-