ActiveMq 简单使用
来源:互联网 发布:淘宝亲宝贝平台的卖家 编辑:程序博客网 时间:2024/05/24 07:36
一. 生产者(消息发送者)
1.创建连接
private String userName = “”;
private String password = “”;
private String brokerURL = “tcp://127.0.0.1:61616”;
2. connection的工厂
private ConnectionFactory factory = new ActiveMQConnectionFactory(userName, password, brokerURL);
3. 连接对象
private Connection connection = factory.createConnection();
connection.start();
4. 会话
private Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);//具体参数自己定
5. Destination
private Destination destination = session.createQueue(“text-msg”);//创建名为text-msg的队列
6. 生产者(消息发送者
private MessageProducer producer = session.createProducer(destination);
7. 发送消息
TextMessage textMsg = session.createTextMessage(“发送消息”);
producer.send(textMsg);
二. 消费者(消息接收者)
1.创建连接
private String userName = “”;
private String password = “”;
private String brokerURL = “tcp://127.0.0.1:61616”;
2. connection的工厂
private ConnectionFactory factory = new ActiveMQConnectionFactory(userName, password, brokerURL);
3. 连接对象
private Connection connection = factory.createConnection();
connection.start();
4. 会话
private Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);//具体参数自己定
5. Destination
private Destination destination = session.createQueue(“text-msg”);//接收对应队列名
6. 消费者(消息接收者)
private MessageConsumer consumer = session.createConsumer(destination);
7. 接收消息
TextMessage message= (TextMessage) consumer.receive(100000);
String text = ((TextMessage)message).getText();
结语:
在http://127.0.0.1:8161/admin/中可以看到消息的发送接收情况,用户名密码都是admin
注:
如果结合spring使用,最好使用5.12.0之前的版本,之后的版本包含了spring会引起冲突而报错,或者剔除掉spring的内容再引入,不然tomcat都启动不了哦
- ActiveMQ简单使用介绍
- ActiveMQ的简单使用
- ActiveMq的简单使用
- ActiveMQ的简单使用
- Activemq的简单使用
- ActiveMQ的简单使用
- ActiveMQ的简单使用
- ActiveMQ的简单使用
- 简单使用ActiveMQ
- ActiveMq 简单使用
- ActiveMq简单使用
- ubuntu下简单使用activemq
- ActiveMQ安装和简单使用
- activeMQ搭建和简单使用
- java消息队列ActiveMQ的简单使用
- java消息队列ActiveMQ的简单使用
- Maven的ActiveMQ+spring的简单使用
- ActiveMQ简单使用(二):整合Spring
- 法兰距大全
- Centos7中搭建最新版nexus3_maven私服
- Token生成规则以及工具
- Oracle 时间戳 日期
- qt上位机,将下位机发送数据解码显示实时曲线
- ActiveMq 简单使用
- Git 常用操作(十二) 生成ssh key
- 【hbase】thrift2 集群 && 指定端口
- ubuntu 主题美化
- 利用dwebsocket在Django中使用Websocket
- 游戏开发学习笔记(四)虚拟摇杆的制作
- King of Destruction HDU
- EOJ 3322 万年历(历史题)
- Raft对比ZAB协议