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 我们每天都要查看服务器的日志,一方面是为了开发的同事翻找日志,另一方面是巡检服务器查看日志,而随着服务器数量以及越来越多的业务上线,日志越来越多,人肉运维相当痛苦了,此时,参考现在非常 ...
随机推荐
- 期待已久的2012年度最佳jQuery插件揭晓
近日,国外著名博客WDL发布了2012年度最佳 jQuery 插件.jQuery 自2006年发布以来,经过6年的迅速发展,目前已是最流行和使用最广泛的 JavaScript 框架,这主要归功于众多围 ...
- spring-- 事务--9
9.1 数据库事务概述 事务首先是一系列操作组成的工作单元,该工作单元内的操作是不可分割的,即要么所有操作都做,要么所有操作都不做,这就是事务. 事务必需满足ACID(原子性.一致性.隔离性和持久性 ...
- CodeForces 370A Rook, Bishop and King
此题看似很简单,但实际上有不少细节,WA点不少.分情况处理即可. #include<cmath> #include<cstdio> #include<string> ...
- 用Oracle的TRIM函数去除字符串首尾指定字符
去掉首尾空格 SELECT TRIM(' abc '), ltrim(' abc '), rtrim(' abc ') FROM dual; 去掉首尾的其他字符 SELECT /*TRIM(';a;b ...
- linux内核中分配4M以上大内存的方法
在内核中, kmalloc能够分配的最大连续内存为2的(MAX_ORDER-1)次方个page(参见alloc_pages函数, "if (unlikely(order >= ...
- bzoj 2282 [Sdoi2011]消防(树的直径,二分)
Description 某个国家有n个城市,这n个城市中任意两个都连通且有唯一一条路径,每条连通两个城市的道路的长度为zi(zi<=1000). 这个国家的人对火焰有超越宇宙的热情,所以这个国家 ...
- HW4.4
public class Solution { public static void main(String[] args) { final double KILOMETERS_PER_MILE = ...
- POJ3641-Pseudoprime numbers(快速幂取模)
题目大意 判断一个数是否是伪素数 题解 赤果果的快速幂取模.... 代码: #include<iostream> #include<cmath> using namespace ...
- Dynamices CRM JS 类库 神器 XrmServiceToolkit - A Microsoft Dynamics CRM 2011 & CRM 2013 JavaScript Library
XrmServiceToolkit - A Microsoft Dynamics CRM 2011 & CRM 2013 JavaScript Library http://xrmservic ...
- .NET Compact Framework Data Provider for SQL Server CE
.NET Compact Framework Data Provider for SQL Server Mobile Standard Data Source=MyData.sdf;Persist S ...