从官网下载
Windows环境下,下载完之后直接解压,直接在bin/win64(选择和电脑系统一样的)点击activemq.bat即可运行
在浏览器中可以直接方位web页面http://127.0.0.1:8161/admin
默认用户名和密码都是admin
配置文件org.springframework.boot spring-boot-starter-activemq org.springframework spring-jms org.apache.activemq activemq-client
注意ActiveMQ默认连接的端口是61616,默认为点对点模式
spring:
activemq:
broker-url: tcp://127.0.0.1:61616
pool:
max-connections: 100
创建生产者
@Autowired 注解, JmsTemplate 对象注入进来,send() 方法中调用 JmsTemplate 对象的 convertAndSend 来转换并发送消息。
@Component
public class ActiveMQProduct {
@Autowired
private JmsTemplate jmsTemplate;
public void send(String message) {
jmsTemplate.convertAndSend("hello-active", message);
}
}
创建消费者
@Component
public class ActiveMQConsumer{
@JmsListener(destination="hello-active")
public void receive(String message) {
System.out.println(message);
}
}
启动类
@SpringBootApplication
public class ActivemqHelloServerApplication {
public static void main(String[] args) {
SpringApplication.run(ActivemqHelloServerApplication.class, args);
}
}
注意事项
没有序列化的对象不能作为message发送,如HttpServletResponse



