• 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";
    }
    
  • 相关阅读:
    IT职业选择与定位
    零碎时间应该拿来做什么
    编程漫谈(七):意义与自由
    第一次项目发布的心得体会
    入职一月的一点感想
    职业发展思考(一)
    健康先行: 每天锻炼一小时!!!
    2012, 软件职场之旅启程
    程序员的成长之路
    计算机学习方法
  • 原文地址:https://www.cnblogs.com/ye-hcj/p/9782970.html
Copyright © 2020-2023  润新知