zoukankan      html  css  js  c++  java
  • ActiveMQ 的安装与使用(springboot版本)

    一、安装

    上官网下载tar包

    http://activemq.apache.org/

    tar -zxvf 后进入bin/linux-86-64

    ./activimq start

    启动

    二、使用

    pom文件引入依赖

    <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.47</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-activemq</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.activemq</groupId>
                <artifactId>activemq-pool</artifactId>
            </dependency>
            <dependency>

    application.properties的配置文件

    spring.activemq.broker-url=tcp://39.108.83.105:61616
    #spring.activemq.broker-url=tcp://127.0.0.1:61616
    spring.activemq.user=
    spring.activemq.password=
    spring.activemq.pool.enabled=true
    spring.activemq.pool.max-connections=50
    spring.activemq.pool.expiry-timeout=10000
    spring.activemq.pool.idle-timeout=30000
    
    #主题类型消息这个为true
    spring.jms.pub-sub-domain=true

    生产者代码:

    @Component
    public class JMSProducer {
    
        @Autowired
        private JmsTemplate jmsTemplate;
    
        public void sendMessage(Destination destination, String message) {
            this.jmsTemplate.convertAndSend(destination,message);
        }
    }

    消费者代码:

    @Component
    public class JMSConsumer {
    
        @JmsListener(destination = "myTopic")
        public void receiveQueue(String msg) {
            System.out.println(msg);
        }
    }

    调用类:

        @PostMapping("/postTopic")
        public String postTopic(@RequestBody JSONObject reqBody){
            ActiveMQTopic myTopic = new ActiveMQTopic("myTopic");
            jmsProducer.sendMessage(myTopic,reqBody.toJSONString());
            return "成功";
        }
  • 相关阅读:
    (二) 线程创建、中止、中断、线程Join、优先级、调度
    cmake 生成64位项目
    ffmpeg + sdl player console
    ffmpeg cmd
    ffmpeg coco2d-x lua test
    ffmpeg windows config win32/win64 compile
    ffmpeg configure --help
    ffmpeg Windows platfrom ndk compile ffmpeg
    NDK r21编译FFmpeg 4.2.2(x86、x86_64、armv7、armv8)
    解决NDK交叉编译 selected processor does not support ARM mode libtheora的错误
  • 原文地址:https://www.cnblogs.com/yeyongjian/p/9277309.html
Copyright © 2011-2022 走看看