ActiveMQ
下载MQ后启动一下(Windows版本)
#启动信息
...
jvm 1 | INFO | Listening for connections at ws://JackWen:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600
jvm 1 | INFO | Connector ws started
jvm 1 | INFO | Apache ActiveMQ 5.14.0 (localhost, ID:JackWen-3764-1535341346100-0:1) started
jvm 1 | INFO | For help or more information please see: http://activemq.apache.org
jvm 1 | WARN | Store limit is 102400 mb (current store usage is 4 mb). The data directory: D:\ActiveMQ\apache-activemq-5.14.0\bin\win32\..\..\data\kahadb only has 56508 mb of usable space. - resetting to maximum available disk space: 56508 mb
jvm 1 | INFO | No Spring WebApplicationInitializer types detected on classpath
jvm 1 | INFO | ActiveMQ WebConsole available at http://0.0.0.0:8161/
jvm 1 | INFO | ActiveMQ Jolokia REST API available at http://0.0.0.0:8161/api/jolokia/
jvm 1 | INFO | Initializing Spring FrameworkServlet 'dispatcher'
jvm 1 | INFO | No Spring WebApplicationInitializer types detected on classpath
jvm 1 | INFO | jolokia-agent: Using policy access restrictor classpath:/jolokia-access.xml
jvm 1 | INFO | Connector vm://localhost started
jvm 1 | WARN | Transport Connection to: tcp://127.0.0.1:4013 failed: java.net.SocketException: Connection reset
与SpringBoot项目整合
pom.xml
<!--activeMQ-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
application.properties
#ActiveMQ
spring.activemq.broker-url=tcp://localhost:61616
生产者:
implements MessageCreator
/**
* 消息生产者
*/
public class Producer implements MessageCreator {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("消息生产者创建的一条消息");
}
}
消费者:
@JmsListener(destination = "xxx")
@Component
public class Consumer {
@JmsListener(destination = "message_LPMQ")
public void getMessage(String message){
System.out.println(message);
}
}
SpringBoot启动类测试:
@Autowired JmsTemplate and implements CommandLineRunner
@SpringBootApplication
public class SpringbootdemoApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemoApplication.class, args);
}
/**
* MQ: 发送消息
*/
@Autowired
private JmsTemplate jmsTemplate;
@Override
public void run(String... args) throws Exception {
jmsTemplate.send("message_LPMQ",new Producer());
}
}