zoukankan      html  css  js  c++  java
  • activemq artemis安装运行及其在springboot中的使用

    安装

    http://activemq.apache.org/artemis/download.html
    

    创建broker

    将artemis解压完成后,在重新建一个文件夹artmisbroker
    
    运行
    artemis.cmd create C:artmisbroker --user mq --password 123
    即可在artmisbroker目录下生成所需的文件
    
    运行artemis 
    "C:artmisbrokerinartemis" run
    
    使用Windows service方式运行artemis
    "C:artmisbrokerinartemis-service.exe" install
    "C:artmisbrokerinartemis-service.exe" start
    
    停止 windows service:
    "C:artmisbrokerinartemis-service.exe" stop
    
    卸载windows service
    "C:artmisbrokerinartemis-service.exe" uninstall
    
    访问 http://localhost:8161/console 进入监视界面
    

    在springboot中的使用

    依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-artemis</artifactId>
        <version>2.0.5.RELEASE</version>
    </dependency>
    

    配置

    spring.artemis.mode=native
    spring.artemis.host=localhost
    spring.artemis.port=61616
    spring.artemis.user=mq
    spring.artemis.password=123
    

    Producer

    @Component
    public class Producer {
     
        @Autowired
        private JmsMessagingTemplate jmsMessagingTemplate;
     
        public void send(Destination destination, final String message) {
            jmsMessagingTemplate.convertAndSend(destination, message + "from queue");
        }
    
        @JmsListener(destination="out.queue")
    	public void consumerMessage(String text){
    		System.out.println("从out.queue队列收到的回复信息为:"+text);
    	}
    }
    

    Consumer

    @Component
    public class Consumer {
        @JmsListener(destination = "mytest.queue")
        @SendTo("out.queue")
    	public String receiveQueue(String text) {
            System.out.println("Consumer收到的信息为:"+text);
            return "return message "+text;
    	}
    }
    

    Rest使用

    @ResponseBody
    @RequestMapping(value = "/mqtest", method = RequestMethod.GET)
    public Object mqtest() {
        Destination destination = new ActiveMQQueue("mytest.queue");
        producer.send(destination, "I am YeJiaWei");
        return "OK";
    }
    
  • 相关阅读:
    在Centos 7下编译openwrt+njit-client
    开博随笔
    Chapter 6. Statements
    Chapter 4. Arrays and Pointers
    Chapter 3. Library Types
    Chapter 2.  Variables and Basic Types
    关于stm32不常用的中断,如何添加, 比如timer10 timer11等
    keil 报错 expected an identifier
    案例分析 串口的地不要接到电源上 会烧掉
    案例分析 CAN OPEN 调试记录 进度
  • 原文地址:https://www.cnblogs.com/ye-hcj/p/9782970.html
Copyright © 2011-2022 走看看