分布式-信息方式-ActiveMQ示例
实战
代码如下:
信息生产者
package test.mq.helloword; import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory; public class Sender {
public static void main(String[] args) throws JMSException, InterruptedException {
ConnectionFactory ConnectionFactory=new ActiveMQConnectionFactory(
"tcp://localhost:61616"
);
Connection connection=ConnectionFactory.createConnection();
connection.start();
Session session=connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination destination=session.createQueue("my_queue");
MessageProducer Producer=session.createProducer(destination); for(int i=;i<=;i++){
TextMessage message=session.createTextMessage("message----"+i);
//Thread.sleep(1000);
Producer.send(message);
}
session.commit();
session.close();
connection.close();
}
}
ActiveMQ页面

信息消费者
package test.mq.helloword; import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.ConsumerBrokerExchange; public class Receiver { public static void main(String[] args) throws JMSException {
ConnectionFactory ConnectionFactory=new ActiveMQConnectionFactory(
"tcp://localhost:61616"
);
Connection connection=ConnectionFactory.createConnection();
connection.start();
Session session=connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
Destination destination=session.createQueue("my_queue");
MessageConsumer Consumer=session.createConsumer(destination); while(true){
TextMessage msg=(TextMessage) Consumer.receive();
msg.acknowledge();
if(msg==null)break;
System.out.println("接收信息:------》"+msg.getText());
}
if(connection!=null){
connection.close();
}
} }
控制台

ActiveMQ页面

分布式-信息方式-ActiveMQ示例的更多相关文章
- 分布式-信息方式-ActiveMQ的Destination高级特性3
虚拟destination用来创建逻辑destination,客户端可以通过它来生产和消费消息,它会把消息映射到物理destination. ActiveMQ支持2种方式: 1:虚拟主题(Virtua ...
- 分布式-信息方式-ActiveMQ静态网络连接的容错
容错的链接Failover Protocol 前面讲述的都是client配置链接到指定的 broker上.但是,如果 Broker的链接失败怎么办呢?此时, Client有两个选项:要么立刻死掉,要么 ...
- 分布式-信息方式-ActiveMQ的消息存储持久化
ActiveMQ的消息存储持久化■概述ActiveMQ不仅支持 persistent和 non-persistent两种方式,还支持消息的恢复( recovery)方式PTPQueue的存储是很简单的 ...
- 分布式-信息方式-ActiveMQ的Message dispatch高级特性之(指针) Message cursors
Message dispatch高级特性之 Message cursors概述 ActiveMQ发送持久消息的典型处现方式是:当消息的消费者准备就绪时,消息发送系统把存储的 消息 ...
- 分布式-信息方式-ActiveMQ的Destination高级特性2
使用filtered destinations,在xml配置如下: <destinationInterceptors> <virtualDestinationInterceptor& ...
- 分布式-信息方式-ActiveMQ的Destination高级特性1
ActiveMQ的Destination高级特性 Destination高级特性----->Composite Destinations 组合队列Composite Destinations : ...
- 分布式-信息方式-ActiveMQ的集群
ActiveMQ的集群Queue consumer clusters ActiveMQ支持 Consumer对消息高可靠性的负载平衡消费,如果一个 Consumer死掉,该消 ...
- 分布式-信息方式-ActiveMQ的动态网络链接
ActiveMQ的动态网络链接多播协议 multicast ActiveMQ使用 Multicast协议将一个 Service和其他的 Broker的 Service连接起来,IPmulticast是 ...
- 分布式-信息方式-ActiveMQ静态网络连接信息回流功能
“丢失”的消息 有这样的场景, broker1和 broker2通过 netwoskconnector连接,一些 consumers连接到 broker1,消费 broker2上的消息.消息先被 br ...
随机推荐
- Buy a Ticket CodeForces - 938D (dijkstra)
大意: n节点无向图, 点$i$到点$j$的花费为$2dis(i,j)+a[j]$, 对于每个点, 求最少花费. 每条边权翻倍, 源点S向所有点$i$连边, 权为$a[i]$, 答案就为$S$到每个点 ...
- luogu P4006 小 Y 和二叉树
luogu loj 可以发现度数\(< 3\)的点可以作为先序遍历的第一个点,那么就把度数\(< 3\)的编号最小的点作为第一个点.然后现在要确定它的左右儿子(或者是右儿子和父亲).我们把 ...
- Flask与微信小程序登录(后端)
开发微信小程序时,接入小程序的授权登录可以快速实现用户注册登录的步骤,是快速建立用户体系的重要一步.这篇文章将介绍 python + flask + 微信小程序实现用户快速注册登录方案(本文主要进行后 ...
- 25 Python之模块与包
一.模块 模块就是一个包含了python定义和申明的文件,文件名就是模块的名字加上.py的后缀/ 模块的分类: 1.使用python编写的py文件 2.已被编译位共享库或者DLL或 ...
- This application has no explicit mapping for /error, so you are seeing this as a fallback.
检查url是否输入正确,要加上之前的mapping映射
- 在Chrome中使用IE浏览器!
学校的毕业论文系统,无法完整显示网页,特别是下部的"提交"按钮看不见. IE11无效. 发现"360极速浏览器 7.5.3.186"能正常显示,百度网盘下载太慢 ...
- 【版本控制工具】 Git基础
一.Git简介 Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.于是Git 成了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件. (Git目前使用率非常 ...
- kubeDNS workflow(service registration and discovery)
Service discovery In k8s, we usually will more than make an application instance, and also the corre ...
- mysql向表中某字段前后追加一段字符串 concat(), trim(), ltrim(), rtrim(), repeat()
1.mysql向表中某字段后面追加一段字符串:update table_name set field=CONCAT(field, '分隔符', str);//'分隔符',可以为空,也可以省略updat ...
- Automatches
import os def combine(ArrayList,count): ArrayList=list(ArrayList) newArrayList=[] for i in range(0,A ...