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+".....");
        }
    }
  • 相关阅读:
    Java的Integer与int互转
    浅析Java中的final关键字
    zookeeper leader作用
    闭包的潜在用处
    Keystone controller.py & routers.py代码解析
    zookeeper 同步
    elk 分布式数据同步
    mget 同时获取
    Elasticsearch 单模式下API的增删改查操作
    安装 插件,查看插件
  • 原文地址:https://www.cnblogs.com/mingforyou/p/14655298.html
Copyright © 2011-2022 走看看