<!-- 添加acitivemq依赖 --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId></dependency>
- 增加Application类
@SpringBootApplication@EnableScheduling //使用定时任务发送消息public class MqTestApplication { public static void main(String[] args) { SpringApplication.run(MqTestApplication.class, args); }}
- 配置application.yml
spring: activemq: broker-url: tcp://127.0.01:61616 packages: trust-all: true
- 构建一个数据Model,可以发送和消费的数据类型有: String, byte array, Map<String,?>, Serializable object.
// 如果发送的消息是一个对象,必须implements Serializable接口public class TModel implements Serializable { private static final long serialVersionUID = -921008687184331557L; private int count; public TModel(int count) { this.count = count; } @Override public String toString() { return "TModel [count=" + count + "]"; }
注:本文内容来自互联网,旨在为开发者提供分享、交流的平台。如有涉及文章版权等事宜,请你联系站长进行处理。