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:\artmisbroker\bin\artemis" run

使用Windows service方式运行artemis
"C:\artmisbroker\bin\artemis-service.exe" install
"C:\artmisbroker\bin\artemis-service.exe" start

停止 windows service:
"C:\artmisbroker\bin\artemis-service.exe" stop

卸载windows service
"C:\artmisbroker\bin\artemis-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";
}

转载于:https://www.cnblogs.com/ye-hcj/p/9782970.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值