ActiveMQ系列(1) - 使用入门
- 1.背景:
- 2.系统环境:
windows 10 企业版本 64位
- 3.获取 与 安装 :
a) http://activemq.apache.org/ 自行选择中意版本(或 文章底部,我上传了,是目前的最新版本), 注意看域名,apache,所以肯定离不开 jdk了, jdk获取:


- 4 安装使用:







- 5. 参考 p2p 案例代码:
namespace TestActiveMQ
{
class Program
{
private static IConnectionFactory factory //需要引用 Apache.NMS;
= new ConnectionFactory("tcp://localhost:61616");//需要引用Apache.NMS.ActiveMQ; static void Main(string[] args)
{
//建立连接
using (IConnection connection = factory.CreateConnection())
{
//通过连接创建session会话
using (ISession session = connection.CreateSession())
{
//通过会话创建生产者,方法里面new出来的是MQ中的Queue
IMessageProducer producer = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("firstQueue"));
//创建一个发送的消息对象
ITextMessage message = producer.CreateTextMessage(); //给这个对象赋实际的消息
message.Text = "";
//设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性
message.Properties.SetString("filter", "demo");
//生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位,当然还有其他重载
producer.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); Console.WriteLine("发送成功!");
Console.ReadLine();
}
} }
}
}
客户端:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitConsumer();
} public void InitConsumer()
{
//创建连接工厂
IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
//通过工厂构建连接
IConnection connection = factory.CreateConnection();
//这个是连接的客户端名称标识
connection.ClientId = "firstQueueListener";
//启动连接,监听的话要主动启动连接
connection.Start();
//通过连接创建一个会话
ISession session = connection.CreateSession();
//通过会话创建一个消费者,这里就是Queue这种会话类型的监听参数设置
IMessageConsumer consumer = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("firstQueue"), "filter='demo'");
//注册监听事件
consumer.Listener += new MessageListener(consumer_Listener);
//connection.Stop();
//connection.Close(); } void consumer_Listener(IMessage message)
{
ITextMessage msg = (ITextMessage)message;
//异步调用下,否则无法回归主线程
tbReceiveMessage.Invoke(new DelegateRevMessage(RevMessage), msg); } public delegate void DelegateRevMessage(ITextMessage message); public void RevMessage(ITextMessage message)
{
tbReceiveMessage.Text += string.Format(@"接收到:{0}{1}", message.Text, Environment.NewLine);
} }
执行结果:

ActiveMQ系列(1) - 使用入门的更多相关文章
- 分布式学习系列【dubbo入门实践】
分布式学习系列[dubbo入门实践] dubbo架构 组成部分:provider,consumer,registry,monitor: provider,consumer注册,订阅类似于消息队列的注册 ...
- 「译」JUnit 5 系列:基础入门
原文地址:http://blog.codefx.org/libraries/junit-5-basics/ 原文日期:25, Feb, 2016 译文首发:Linesh 的博客:JUnit 5 系列: ...
- ActiveMQ系列之五:ActiveMQ的Transport
连接到ActiveMQ Connector:ActiveMQ提供的,用来实现连接通讯的功能.包括:client-to-broker.broker-to-broker. ActiveMQ允许客户端使用多 ...
- ActiveMQ系列之四:用ActiveMQ构建应用
Broker:相当于一个ActiveMQ服务器实例 命令行启动参数示例如下: 1:activemq start :使用默认的activemq.xml来启动 2:activemq start xbean ...
- ActiveMQ系列之三:理解和掌握JMS
JMS是什么 JMS Java Message Service,Java消息服务,是Java EE中的一个技术. JMS规范 JMS定义了Java 中访问消息中间件的接口,并没有给予实现,实现JMS ...
- ActiveMQ系列之二:ActiveMQ安装和基本使用
下载并安装ActiveMQ服务器端 1:从http://activemq.apache.org/download.html下载最新的ActiveMQ 2:直接解压,然后拷贝到你要安装的位置就好了 启动 ...
- ActiveMQ系列之一:ActiveMQ简介
ActiveMQ是什么 ActiveMQ是Apache推出的,一款开源的,完全支持JMS1.1和J2EE 1.4规范的JMS Provider实现的消息中间件 (Message Oriented ...
- SpringBoot系列: RestTemplate 快速入门
====================================相关的文章====================================SpringBoot系列: 与Spring R ...
- Go基础系列:channel入门
Go channel系列: channel入门 为select设置超时时间 nil channel用法示例 双层channel用法示例 指定goroutine的执行顺序 channel基础 chann ...
- elk系列1之入门安装与基本操作【转】
preface 我们每天都要查看服务器的日志,一方面是为了开发的同事翻找日志,另一方面是巡检服务器查看日志,而随着服务器数量以及越来越多的业务上线,日志越来越多,人肉运维相当痛苦了,此时,参考现在非常 ...
随机推荐
- .NET平台上的Memcached客户端介绍(Memcached Providers)
早上接到一个任务,需要对Linux服务器的Memcached的update操作进行性能测试,我发现我是一个典型的“手里拿着锤子,就把所有问题都当成钉子”的人.我第一个念头就是,上Memcached的官 ...
- Selenium RC 环境搭建(eclipse)
环境搭建参考:http://seleniumcn.cn/read.php?tid=7962 非常详细!晕乎晕乎了两天,看到这边帖子,终于搭起来了. 关于Selenium RC的原理,还是Seleni ...
- ionic如何uglify和minify你的js,css,image,png....
Install: 1.ionic start myapp blank 2.cd myapp 3.npm install cordova-uglify or npm install ...
- ssh -CT -o BatchMode=yes 用户名@主机名
- PC-红警联机问题与下载
或许不是软件问题: 你做好相关设置了吗? 红警局域网联机的具体方法: 适用于原版红警.尤里复仇,及任何同样的扩展版. 第一步:安装IPX协议. 方法: 控制面板——网络连接(或网上邻居·属性)——本地 ...
- python 多行字符串
字符串是要用引号(双引号,单引号,多行用三个引号)引起来 TypeError: not enough arguments for format string you have to specify m ...
- ios 好去处
1.王巍的博客(我们都叫它喵神,他很萌哒) 链接:http://onevcat.com/ (难度指数:※※※※※)理由:他的swift的新书讲解的非常好,但不适合入门,进阶的话这是很适合的一本书.其他 ...
- Asp.Net的应用程序生命周期概述
参考文献: MSDN:Asp.Net应用程序生命周期 博客:选择HttpHandler还是HttpModule? 1.HttpModule 应用程序(HttpApplication)引发的事件可以由实 ...
- 使用cxf写web service的简单实例
增加CXF依赖 <dependency> <groupId>org.apache.cxf</groupId> <artifactId>apache-cx ...
- GridControl 选择列、复选框全选(下)
功能: 删除选中行 前台调用: string str=""; GridDelete(gv, "chk", out str); MessageBox ...