Home > Software design >  Spring Boot Embedded ActiveMQ Artemis with listener
Spring Boot Embedded ActiveMQ Artemis with listener

Time:05-06

I'm trying to set up a couple of tiny applications - as a demonstration of some new tooling - that communicate via ActiveMQ Artemis. Because it's just a demo, I'm trying to make things as easy as possible for the end-users. As such, I was going the route of the embedded Artemis support that Spring Boot now has.

I've got this working great. However, I can't work out how to make this also listen on a local port so that other services can connect to it as well.

Essentially what I want to do is:

  • Service A
    • Starts an embedded Artemis as part of service startup
    • Allow this Artemis server to be connected to by other services <-- This Bit Here
    • Has a consumer listening to a queue on this embedded Artemis
  • Service B
    • Connects to the Artemis running in Service A <-- And This Bit Here
    • Has an HTTP endpoint that produces messages onto a queue on that Artemis service

I've marked the bits that I can't (yet) work out how to do.

For reference, my application.properties is currently this:

server.port=8082

spring.artemis.mode=EMBEDDED
spring.artemis.host=localhost
spring.artemis.port=61616

spring.artemis.embedded.enabled=true

spring.jms.template.default-destination=my-queue-1

logging.level.org.apache.activemq.audit.base=DEBUG
logging.level.org.apache.activemq.audit.message=DEBUG

Is it possible to make this work? Or do I need to have people run an external Artemis service instead?

Cheers

Edit. Artemis isn't essential. It just needs to be some asynchronous messaging platform. If it can be done with ActiveMQ Classic, RabbitMQ or anything else then that's fine.

CodePudding user response:

By default Spring will only allow in-vm connections to the embedded instance of ActiveMQ Artemis. See the use of InVMAcceptorFactory in ArtemisEmbeddedConfigurationFactory.

To change this you need to add a new Acceptor to your Artemis configuration through a custom ArtemisConfigurationCustomizer bean, e.g.:

import org.springframework.boot.autoconfigure.jms.artemis.ArtemisConfigurationCustomizer;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ArtemisConfig implements ArtemisConfigurationCustomizer {
   @Override
   public void customize(org.apache.activemq.artemis.core.config.Configuration configuration) {
      configuration.addAcceptorConfiguration("remote", "tcp://0.0.0.0:61616");
   }
}
  • Related