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 SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic enumFeature flags for the methodnewActiveMqBroker(ActiveMq...)- which you probably shouldn't do unless you are experimenting with the "mats-examples".static classEither creates an in-vm ActiveMQ, or an ActiveMQ ConnectionFactory to an external URL, based on system properties.static classCreates a connection to an Artemis broker.static classCreates an in-vm ActiveMQ no matter what the properties says.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringWhich Broker client to use (which JMSConnectionFactoryimplementation): 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 StringDEFAULT: Use ActiveMQ as broker.static final StringUse Artemis (Apache ActiveMQ Artemis) as broker - this was formerly JBoss HornetQ.static final StringUse RabbitMQ as broker.static final StringSystem 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 StringDEFAULT: If the value ofSYSPROP_MATS_TEST_BROKERURLis this value OR not set (i.e.static final StringIf the value ofSYSPROP_MATS_TEST_BROKERURLis this value, it means default localhost connection string foractive broker, e.g.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Stops the created in-vm broker, if it was created (readSYSPROP_MATS_TEST_BROKERURL).static MatsTestBrokercreate()static MatsTestBrokerThis is a special factory method, which creates a unique (randomly named) in-vm ActiveMQ instance, no matter what the system properties says.javax.jms.ConnectionFactorystatic org.apache.activemq.broker.BrokerServicenewActiveMqBroker(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 methodMatsTestBrokerclass directly, using itscreate()method.
- 
Field Details- 
SYSPROP_MATS_TEST_BROKERWhich Broker client to use (which JMSConnectionFactoryimplementation): 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_ACTIVEMQDEFAULT: Use ActiveMQ as broker.- See Also:
 
- 
SYSPROP_MATS_TEST_BROKER_VALUE_ARTEMISUse Artemis (Apache ActiveMQ Artemis) as broker - this was formerly JBoss HornetQ.- See Also:
 
- 
SYSPROP_MATS_TEST_BROKER_VALUE_RABBITMQUse RabbitMQ as broker. This cannot be used in embedded mode, since RabbitMQ is written in Erlang.- See Also:
 
- 
SYSPROP_MATS_TEST_BROKERURLSystem 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_VMDEFAULT: If the value ofSYSPROP_MATS_TEST_BROKERURLis 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_LOCALHOSTIf the value ofSYSPROP_MATS_TEST_BROKERURLis 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!).
 
- 
createUniqueInVmActiveMqThis 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.
 
- 
getConnectionFactoryjavax.jms.ConnectionFactory getConnectionFactory()- Returns:
- the ConnectionFactory connecting to the broker.
 
- 
closevoid 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.
- 
newActiveMqBrokerstatic 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 methodMatsTestBrokerclass 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.
 
 
-