• Springboot 2.2.1 与activeMq 集成2 topic 发布者,订阅者


    在ProducerService接口中,增加下面这个方法

    /**
    * 功能描述:消息发布者
    * @param msg
    */
    void publish(String msg);

    在实现类:ProducerServiceImpl 添加:
    //=======发布订阅相关代码=========

    @Autowired
    private Topic topic;


    @Override
    public void publish(String msg) {
    jmsTemplate.convertAndSend(topic, msg);
    }


    controller中:OrderController

    @GetMapping("publish")
    public String publish(String msg){
    producerService.publish(msg);
    return "publish";
    }






    //订阅者 监听发布
    package com.active.mq.listener;
    
    import org.springframework.jms.annotation.JmsListener;
    import org.springframework.stereotype.Component;
    
    /**
     * 订阅者监听
     *
     * @author kql
     */
    @Component
    public class TopicSub {
    //这里指定监听的消息 video.topic 也可自定义监听
    
        @JmsListener(destination = "video.topic", containerFactory = "jmsListenerContainerTopic")
        public void receive1(String text) {
            System.out.println("video.topic 消费者:receive1=" + text);
        }
    
    
        @JmsListener(destination = "video.topic", containerFactory = "jmsListenerContainerTopic")
        public void receive2(String text) {
            System.out.println("video.topic 消费者:receive2=" + text);
        }
    
    
        @JmsListener(destination = "video.topic", containerFactory = "jmsListenerContainerTopic")
        public void receive3(String text) {
            System.out.println("video.topic 消费者:receive3=" + text);
        }
    
    
    }

    http://localhost:8080/publish?msg=订阅  

  • 相关阅读:
    css去掉iPhone、iPad默认按钮样式
    STL~Deque简介
    Centos 7 ssh登录速度慢
    C++ delete 两次
    编译gdb 报错 No module named gdb.frames
    gdb 脚本
    转载: CentOS/Linux 解决 SSH 连接慢
    百度经验:Win10查看已存储WiFi密码的两种方法
    git 操作
    Avoiding memory leaks in POSIX thread programming, 多线程避免内存泄漏
  • 原文地址:https://www.cnblogs.com/woshuaile/p/11907361.html
Copyright © 2020-2023  润新知