First, installation
Web Download Tar Package
http://activemq.apache.org/
TAR-ZXVF after entering bin/linux-86-64
./activimq Start
Start
Second, use
Pom File Introduction Dependency
<dependency> <groupId>com.alibaba</groupId> <artifactid>fastjson</ artifactid> <version>1.2.47</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq< /artifactid> </dependency> <dependency> <groupid>org.apache.activemq</ groupid> <artifactId>activemq-pool</artifactId> </dependency> < Dependency>
Configuration file for Application.properties
SPRING.ACTIVEMQ.BROKER-URL=TCP://39.108.83.105:61616#spring. ACTIVEMQ.BROKER-URL=TCP:// 127.0.0.1:61616spring.activemq.user=spring.activemq.password= spring.activemq.pool.enabled=truespring.activemq.pool.max-connections=50 Spring.activemq.pool.expiry-timeout=10000spring.activemq.pool.idle-timeout=30000# Topic type Message This is Truespring.jms.pub-sub-domain=true
Producer Code:
@Component Public class JMSProducer { @Autowired private jmstemplate jmstemplate; Public void sendMessage (Destination Destination, String message) { this. Jmstemplate.convertandsend (destination,message); }}
Consumer Code:
@Component Public class Jmsconsumer { = "MyTopic") publicvoid receivequeue (String msg) { System.out.println (msg);} }
Call class:
@PostMapping ("/posttopic") public String posttopic (@RequestBody jsonobject reqbody) { New Activemqtopic ("MyTopic"); Jmsproducer.sendmessage (Mytopic,reqbody.tojsonstring ()); return "Success"; }
Installation and use of ActiveMQ (Springboot version)