Aries' Blog

Freestyle technical blog

Artemis MQ with Springboot

ArtemisMQ is successor of ActiveMQ, using it with springboot is easy as auto-configuration is provided by spring-boot-starter-artemis. A starter project is created here. Below are some notes in using the starter project.

1. Artemis mode in Springboot config

There are 2 modes for the configuration spring.artemis.mode:

  • embedded
    Server mode, embed Artemis Server into the springboot app. Note: By default embedded server only accept internal connection. See point 2 to allow external connection.
  • native
    Client mode, no Artemis Server included. A JmsTemplate will be auto-configured for connecting to the Artemis Server specified by host & port properties.
          mode: native  # client mode
          host: localhost
          port: 61616

2. Allow embedded Artemis server to receive external connection

By default embedded Artemis won’t accept external connection. To allow this, edit springboot default config with below code.

public class ArtemisConfig implements ArtemisConfigurationCustomizer {
    public void customize(org.apache.activemq.artemis.core.config.Configuration configuration) {
        // Allow Artemis to accept tcp connections (Default port localhost:61616)
        configuration.addConnectorConfiguration("nettyConnector", new TransportConfiguration(NettyConnectorFactory.class.getName()));
        configuration.addAcceptorConfiguration(new TransportConfiguration(NettyAcceptorFactory.class.getName()));

3. Artemis auto destination creation feature

There is no need to define destinations (e.g. queue) in Artemis Server as destination are auto created when first use (e.g. incoming message).