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.

  • Field Details

    • SYSPROP_MATS_TEST_BROKER

      static final String SYSPROP_MATS_TEST_BROKER
      Which Broker client to use (which JMS ConnectionFactory 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

      static final String SYSPROP_MATS_TEST_BROKER_VALUE_ACTIVEMQ
      DEFAULT: Use ActiveMQ as broker.
      See Also:
    • SYSPROP_MATS_TEST_BROKER_VALUE_ARTEMIS

      static final String 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

      static final String 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

      static final String SYSPROP_MATS_TEST_BROKERURL
      System property ("-D" jvm argument) that if set to something else than SYSPROP_MATS_TEST_BROKERURL_VALUE_IN_VM, will
      1. Not start an embedded ("in-VM") ActiveMQ instance.
      2. 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 for active broker, e.g. for ActiveMQ: "tcp://localhost:61616"

      Value is "mats.test.brokerurl"

      See Also:
    • SYSPROP_MATS_TEST_BROKERURL_VALUE_IN_VM

      static final String SYSPROP_MATS_TEST_BROKERURL_VALUE_IN_VM
      DEFAULT: If the value of SYSPROP_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 the active 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

      static final String SYSPROP_MATS_TEST_BROKERURL_VALUE_LOCALHOST
      If the value of SYSPROP_MATS_TEST_BROKERURL is this value, it means default localhost connection string for active broker, e.g. for ActiveMQ: "tcp://localhost:61616".

      Value is "localhost"

      See Also:
  • Method Details

    • create

      static MatsTestBroker create()
      Returns:
      a MatsTestBroker implementation respecting the system properties set (defaults are probably good!).
    • createUniqueInVmActiveMq

      static MatsTestBroker 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 (read SYSPROP_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 method MatsTestBroker class directly, using its create() 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.