Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

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

I've read several examples about jms support in spring boot.

and usually sender, receiver and active-mq(actually it can be any other jms compatible message broker) locates within the same application.

I know that I can use stand alone active mq and use properties:

spring.activemq.broker-url=tcp://192.168.1.210:9876
spring.activemq.user=admin
spring.activemq.password=secret

But I want to have 2 applications:

1- sender (connects to jms from receiver embedded and sends messages there)
2-receiver (up application and embedded activemq)

Is it posiible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...