java – Is it possible to connect to spring boot embedded ActiveMQ instance from another application(started in separate process)?

java – Is it possible to connect to spring boot embedded ActiveMQ instance from another application(started in separate process)?

Just add a BrokerService bean to your application:

@SpringBootApplication
public class So48504265Application {

    public static void main(String[] args) {
        SpringApplication.run(So48504265Application.class, args);
    }

    @Bean
    public BrokerService broker() throws Exception {
        BrokerService broker = new BrokerService();
        broker.addConnector(tcp://localhost:61616);
        return broker;
    }

    @Bean
    public ApplicationRunner runner(JmsTemplate template) {
        return args -> template.convertAndSend(foo, AMessage);
    }

    @JmsListener(destination = foo)
    public void listen(String in) {
        System.out.println(in);
    }

}

and

spring.activemq.broker-url=tcp://localhost:61616

and add this to your pom

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-kahadb-store</artifactId>
</dependency>

Add to your config to access local or remotely

@Bean
public BrokerService broker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.addConnector(tcp://0.0.0.0:61616);
    brokerService.setPersistent(false);
    return broker;
}

java – Is it possible to connect to spring boot embedded ActiveMQ instance from another application(started in separate process)?

Leave a Reply

Your email address will not be published. Required fields are marked *