是否可以从另一个应用程序(在单独的进程中启动)连接到Spring Boot嵌入式ActiveMQ实例? [英] Is it possible to connect to spring boot embedded ActiveMQ instance from another application(started in separate process)?

查看:106
本文介绍了是否可以从另一个应用程序(在单独的进程中启动)连接到Spring Boot嵌入式ActiveMQ实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几个有关Spring Boot支持jms的示例。 / p>

通常是发送者,接收者和active-mq(实际上可以是任何其他与jms兼容的消息代理)都位于同一应用程序内。



我知道我可以使用独立的活动mq和使用属性

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

但是我想有2个应用程序:



1-发送者(从嵌入的接收者连接到jms并在那里发送消息)

2个接收器(up应用程序和嵌入式activemq)



这可能吗?

解决方案

只需添加 BrokerService bean到您的应用程序:

  @SpringBootApplication 
公共类So48504265Application {

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

@Bean
public BrokerService broker()引发异常{
BrokerService broker = new BrokerService();
broker.addConnector( tcp:// localhost:61616);
回报经纪人;
}

@Bean
公共ApplicationRunner运行程序(JmsTemplate模板){
return args-> template.convertAndSend( foo, AMessage);
}

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

}

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

并将其添加到pom

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


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?

解决方案

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>

这篇关于是否可以从另一个应用程序(在单独的进程中启动)连接到Spring Boot嵌入式ActiveMQ实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆