大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

JMS&ActiveMQ教程
基于JMS的消息傳送
ActiveMQ與Spring集成
ActiveMQ與SpringBoot集成
ActiveMQ安全機制
ActiveMQ主從集群

ActiveMQ與SpringBoot集成步驟

消息發(fā)送者

1、創(chuàng)建SpringBoot工程13-activemq-boot-sender作為 消息發(fā)送者

2、在pom.xml文件中添加相關依賴

這個依賴在創(chuàng)建Module的時候,如果勾選了集成ActiveMQ會自動生成

<!--SpringBoot集成ActiveMQ的起步依賴-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

3、 在SpringBoot的核心配置文件application.properties中配置ActiveMQ的連接信息

#配置activemq的連接信息
spring.activemq.broker-url=tcp://192.168.235.128:61616
#目的地
spring.jms.template.default-destination=bootQueue
#默認是緩存了jms的session的,所以主程序發(fā)送完消息后,不會退出
# 改為false主程序才可以退出 從SpringBoot2.1.0以后新增的
spring.jms.cache.enabled=false

4、在com.bjpowernode.activemq.service包下創(chuàng)建一個MessageService類,并提供發(fā)送消息的方法(可以從12-activemq-spring-sender直接拷貝) 

@Service
public class MessageService {
    //這里的JmsTemplate是SpringBoot自動配置的
    @Autowired
    private JmsTemplate jmsTemplate;
    public void sendMessage(){
        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage("Hello,Spring ActiveMQ");
            }
        });
    }
}

5、在SpringBoot的主程序中編寫測試代碼,運行測試發(fā)送消息

@SpringBootApplication
public class Application {
   public static void main(String[] args) {
      //獲取Spring容器
      ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
      //根據(jù)容器獲取bean對象
      MessageService messageService = context.getBean("messageService", MessageService.class);
      //調(diào)用bean對象的方法, 發(fā)送消息
      messageService.sendMessage();
   }
}

6、在ActiveMQ控制臺查看效果

消息接收者

1、 創(chuàng)建SpringBoot工程13-activemq-boot-receiver作為 消息接收者

2、在pom.xml文件中添加相關依賴

這個依賴在創(chuàng)建Module的時候,如果勾選了集成ActiveMQ會自動生成

<!--SpringBoot集成ActiveMQ的起步依賴-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

3、在SpringBoot的核心配置文件application.properties中配置ActiveMQ的連接信息

#配置activemq的連接信息
spring.activemq.broker-url=tcp://192.168.235.128:61616
#目的地
spring.jms.template.default-destination=bootQueue
#默認是緩存了jms的session的,所以主程序發(fā)送完消息后,不會退出
# 改為false主程序才可以退出 從SpringBoot2.1.0以后新增的
spring.jms.cache.enabled=false

4、在com.bjpowernode.activemq.service包下創(chuàng)建一個MessageService類,并提供接收消息的方法(可以從12-activemq-spring-receiver直接拷貝) 

@Service
public class MessageService {
    //這里的JmsTemplate是SpringBoot自動配置的
    @Autowired
    private JmsTemplate jmsTemplate;
    public void receiveMessage(){
        Message message = jmsTemplate.receive();
        if(message instanceof TextMessage){
            try {
                String text = ((TextMessage) message).getText();
                System.out.println("SpringBoot接收到的消息為:" + text);
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }
}

5、在SpringBoot的主程序中編寫測試代碼,運行測試接收消息

SpringBootApplication
public class Application {
   public static void main(String[] args) {
      ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
      //根據(jù)容器獲取bean對象
      MessageService messageService = context.getBean("messageService", MessageService.class);
      //調(diào)用bean對象的方法, 接收消息
      messageService.receiveMessage();
   }
}

6、在ActiveMQ控制臺查看效果

全部教程
主站蜘蛛池模板: 99视频精品全部免费观看 | 久久精品国产这里是免费 | 午夜免费体验 | 国产精品呦呦 | 欧美一级视 | 国产91在线精品福利 | 香香影院在线观看 | 欧美va放荡人妇大片 | 久草午夜 | 手机看片神马午夜片 | 亚洲麻豆视频 | 欧美激情在线精品一区二区 | 狠狠2020 | 色视频网站在线观看 | 夜夜夜夜夜夜爽噜噜噜噜噜噜 | 中国性猛交xxxx乱大交 | 亚洲一在线 | 久久国产精品一区二区 | 久久亚洲精品人成综合网 | 曰本人一级毛片免费完整视频 | 免看一级a一片成人123 | 男人天堂欧美 | 一区二区三区四区产品乱码伦 | 国产高清一级毛片在线不卡 | 日日干夜夜操 | 中国美女一级a毛片录像在线 | 快射视频在线观看 | 97视频免费| 麻豆国产原创最新在线视频 | 国产成人无精品久久久久国语 | 天天操夜夜噜 | 毛片大全在线观看 | 天天做夜夜操 | 在线精品中文字幕福利视频 | 亚洲综合第一欧美日韩中文 | 黄页在线播放网址 | 日韩精品一区二区三区 在线观看 | 亚洲精品你懂的 | 亚洲精品久久久久久动漫剧情 | 国产一区二区三区在线 | 日本综合色 |