2

Is there any way to connect to multiple instances of ActiveMQ Artemis using JMS from a Quarkus app?

I see in the documentation that for both [Qpid JMS - AMQP] and [Artemis JMS] the connection URL in the properties is a String and it's required. Does that mean I can't specify multiple broker URLs to connect to?

I don't want to use camel-quarkus-activemq or camel-quarkus-jms because of this current bug.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
aboudirawas
  • 192
  • 3
  • 21
  • 1
    The extensions only allow for config for injecting a single ConnectionFactory, yes. You could however directly instantiate additional ConnectionFactory instances, passing them whatever alternative config you like. – Robbie Gemmell Sep 09 '20 at 15:24

1 Answers1

2

Just like @Robbie Gemmell pointed out in the comments.

One ConnectionFactory takes the required argument's broker URL. Then for the other ConnectionFactory we can directly instantiate it. Like so:

application.properties

# Configures the Artemis properties.
quarkus.artemis.url=tcp://localhost:61616
quarkus.artemis.username=admin
quarkus.artemis.password=admin

# Broker URL for the second ConnectionFactory
brokerURLService=tcp://remote-service:61616

CamelConfiguration

@ApplicationScoped
public class CamelConfigurationz {

  @Value("${brokerURLService}")
  private String brokerURLService;

  @Named
  public Sjms2Component sjms2(ConnectionFactory connectionFactory) {
    Sjms2Component sjms2 = new Sjms2Component();
    sjms2.setConnectionFactory(connectionFactory);
    return sjms2;
  }

  @Named
  public Sjms2Component sjms2Service(ConnectionFactory amqJmsServiceFactory) {
    Sjms2Component sjms2Service = new Sjms2Component();
    sjms2Service.setConnectionFactory(amqJmsServiceFactory);
    return sjms2Service;
  }

  @Named
  public ActiveMQJMSConnectionFactory amqJmsServiceFactory() throws JMSException {
    ActiveMQJMSConnectionFactory amqJmsServiceFactory = new ActiveMQJMSConnectionFactory();
    amqJmsServiceFactory.setBrokerURL(brokerURLService);
    return amqJmsServiceFactory;
  }

}

Routes

public class CamelRoutes extends EndpointRouteBuilder {

  @Override
  public void configure() throws Exception {

    from(sjms2("inquarkus"))
    .log("got activemq message ---------------------------------")
    .to(sjms2("outquarkus"));
    
    from(sjms2("sjms2Service", "inquarkusService"))
    .log("got activemq message service ---------------------------------")
    .to(sjms2("sjms2Service", "outquarkusService"));

  }

}

It can be done differently thus note that I am using spring di extension as well in the example above to use @Value. Also camel-quarkus-endpointdsl to use EndpointRouteBuilder.

aboudirawas
  • 192
  • 3
  • 21