zoukankan      html  css  js  c++  java
  • SpringBoot整合ActiveMQ

    一、引入外部依赖 https://mvnrepository.com/

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-activemq</artifactId>
        <version>2.4.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-pool</artifactId>
        <version>5.16.1</version>
    </dependency>

    二、代码

    spring.activemq.broker-url=tcp://192.168.1.xxx:61616
    spring.activemq.in-memory=true
    spring.activemq.pool.enabled=false
    spring.activemq.user=admin
    spring.activemq.password=admin
    package com.example.controller;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.jms.core.JmsTemplate;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    public class ActiveMQController {
    
        @Autowired
        private JmsTemplate jmsTemplate;
    
        @RequestMapping("/activeMQ")
        @ResponseBody
        public String tests(){
            jmsTemplate.convertAndSend("testname","testMsg");
            return "ok";
        }
    }
    package com.example.activemq;
    
    import org.springframework.jms.annotation.JmsListener;
    import org.springframework.stereotype.Component;
    
    @Component
    public class Consumer {
    
        @JmsListener(destination = "testName")
        public void receiveMsg(String text){
            System.out.println(text+".....");
        }
    }
  • 相关阅读:
    迭代器
    关于文章cisco漏洞4786
    Python学习目录
    Python的xml模块
    【JS30】Event Capture, Propagation, Bubbling and Once
    mysql安装
    CS193P 第四课笔记 · Hexo
    CSS变量
    在CentOS7上开启和挂载NFS共享
    《Android 编程实战》Chap5_重识IPC
  • 原文地址:https://www.cnblogs.com/mingforyou/p/14655298.html
Copyright © 2011-2022 走看看