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";
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM