对比

http://jm.taobao.org/2016/04/01/kafka-vs-rabbitmq-vs-rocketmq-message-send-performance/

安装

下载地址:http://activemq.apache.org/download.html

安装教程: http://gerrard-ok.iteye.com/blog/1766203

解压缩:

运行: ./activemq start

.Net使用

教程:http://www.cnblogs.com/madyina/p/4121458.html#3249312

下载:http://activemq.apache.org/nms/activemq-downloads.html

还有一个下载地址比较全: http://archive.apache.org/dist/activemq/apache-nms/

控制台:http://ip:8161/

用户名: admin, 密码:admin

发送连接: tcp://192.168.16.23:61616?wireFormat.maxInactivityDuration=0

接收连接:failover:(tcp://192.168.16.23:61616?wireFormat.maxInactivityDuration=0&maxInactivityDurationInitalDelay=30000&connection.AsyncSend=true)

Send方法:

    public class FileUploadedMq : IActiveMq
{
private static string ConnString;
public static ConnectionFactory Factory { get; private set; } //private static IMessageProducer MsgProducer; public static event Action<FileUploadedModel> Recved; static FileUploadedMq()
{
ConnString = dbo.GetDbConnString(MqTypeEnum.FileUpload.ToString()); Factory = new ConnectionFactory(ConnString);
} public void Send(FileUploadedModel Msg)
{
try
{
using (IConnection connection = Factory.CreateConnection())
{
//通过连接创建Session会话
using (ISession session = connection.CreateSession())
{
//通过会话创建生产者,方法里面new出来的是MQ中的Queue
var MsgProducer = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("FileUploaded"));
//创建一个发送的消息对象
var TxtMsg = MsgProducer.CreateTextMessage();
TxtMsg.Properties.SetString("filter", "FileUploaded"); //给这个对象赋实际的消息
TxtMsg.Text = Msg.ToJson();
//设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性
//生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位,当然还有其他重载
MsgProducer.Send(TxtMsg, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue);
}
}
}
catch (Exception ex)
{
InfoTypeEnum.Error.LogTo(ex.Message);
} }
}

注册Receive:

    public class ActiveMq
{
public static FileUploadedMq FileUploaded = new FileUploadedMq();
public static FileResolvedMq FileResolved = new FileResolvedMq();
public static FileFastDfsSavedMq FileFastDfsSaved = new FileFastDfsSavedMq();
// public static EmailUploadMq EmailUpload=new EmailUploadMq(); public static bool RegisteFileUploaded(Action<FileUploadedModel> msgRecv, Action<FileUploadedModel, Exception> ErrorFunc = null)
{
return RegisteMq(MqTypeEnum.FileUpload, o =>
{
if (msgRecv == null) return;
msgRecv(o.FromJson<FileUploadedModel>());
}, (a, b) =>
{
if (ErrorFunc == null) return;
ErrorFunc(a.FromJson<FileUploadedModel>(), b);
});
} public static bool RegisteFileResolved(Action<FileResolvedModel> msgRecv, Action<FileResolvedModel, Exception> ErrorFunc = null)
{
return RegisteMq(MqTypeEnum.FileResolved, o =>
{
if (msgRecv == null) return;
msgRecv(o.FromJson<FileResolvedModel>());
}, (a, b) =>
{
if (ErrorFunc == null) return;
ErrorFunc(a.FromJson<FileResolvedModel>(), b);
});
} public static bool RegisteFileFastDfsSaved(Action<FileFastDfsSavedModel> msgRecv, Action<FileFastDfsSavedModel, Exception> ErrorFunc = null)
{
return RegisteMq(MqTypeEnum.FileFastDfsSaved, o =>
{
if (msgRecv == null) return;
msgRecv(o.FromJson<FileFastDfsSavedModel>());
}, (a, b) =>
{
if (ErrorFunc == null) return;
ErrorFunc(a.FromJson<FileFastDfsSavedModel>(), b);
});
} private static bool RegisteMq(MqTypeEnum Name, Action<string> msgRecv, Action<string, Exception> ErrorFunc)
{
if (msgRecv == null) return false; var QueueName = Name.ToString();
try
{
var factory = FileResolvedMq.Factory; //通过工厂构建连接
IConnection connection = factory.CreateConnection();
//这个是连接的客户端名称标识
//connection.ClientId = Environment.MachineName + "FileResolvedMqListener"; //启动连接,监听的话要主动启动连接
connection.Start();
//通过连接创建一个会话
ISession session = connection.CreateSession();
//通过会话创建一个消费者,这里就是Queue这种会话类型的监听参数设置
IMessageConsumer consumer = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(QueueName));//, "filter='FileResolved'"); session.DeleteDestination(QueueName); //注册监听事件
consumer.Listener += message =>
{
var txt = (ITextMessage)message;
if (txt == null || txt.Text.HasValue() == false) { return; } var model = txt.Text; try
{
msgRecv.Invoke(model);
}
catch (Exception e)
{
InfoTypeEnum.Error.LogTo(QueueName + ":在处理过程出现错误!" + connection.ClientId, model.ToJson(), e.Message); if (ErrorFunc != null)
{
try
{
ErrorFunc(model, e);
}
catch { }
}
}
};
return true;
}
catch (Exception ex)
{
InfoTypeEnum.Error.LogTo(QueueName + ":" + ex.Message);
return false;
}
}
}

问题

1. 查看消息显示: Error!  Exception occurred while processing this request, check the log for more information!

原因: 安装了 JRE8 , 改到 JRE7!

参考:http://bbs.csdn.net/topics/390811825

安装老版本:http://www.java.com/zh_CN/download/faq/other_jreversions.xml

activeMq笔记的更多相关文章

  1. ActiveMQ笔记(7):如何清理无效的延时消息?

    ActiveMQ的延时消息是一个让人又爱又恨的功能,具体使用可参考上篇ActiveMQ笔记(6):消息延时投递,在很多需要消息延时投递的业务场景十分有用,但是也有一个缺陷,在一些大访问量的场景,如果瞬 ...

  2. ActiveMQ笔记(6):消息延时投递

    在开发业务系统时,某些业务场景需要消息定时发送或延时发送(类似:飞信的短信定时发送需求),这时候就需要用到activemq的消息延时投递,详细的文档可参考官网说明,本文只介绍二种常用的用法: 注:本文 ...

  3. ActiveMQ笔记(5):JMX监控

    系统上线运行后,及时监控报警是很必要的手段,对于ActiveMQ而言,主要监控的指标有:MQ本身的健康状况.每个队列的生产者数量.消费者数量.队列的当前消息数等. ActiveMQ支持JMX监控,使用 ...

  4. ActiveMQ笔记(4):搭建Broker集群(cluster)

    上一篇介绍了基于Networks of Borkers的2节点HA方案,这一篇继续来折腾Networks of Brokers,当应用规模日渐增长时,2节点的broker可能仍然抗不住访问压力,这时候 ...

  5. ActiveMQ笔记(3):基于Networks of Brokers的HA方案

    上一篇介绍了基于ZK的ActiveMQ HA方案,虽然理解起来比较容易,但是有二个不足: 1)  占用的节点数过多,1个zk集群至少3个节点,1个activemq集群也至少得3个节点,但其实正常运行时 ...

  6. ActiveMQ笔记(2):基于ZooKeeper的HA方案

    activemq官网给出了3种master/slave的HA方案,详见:http://activemq.apache.org/masterslave.html,基于共享文件目录,db,zookeepe ...

  7. ActiveMQ笔记(1):编译、安装、示例代码

    一.编译 虽然ActiveMQ提供了发布版本,但是建议同学们自己下载源代码编译,以后万一有坑,还可以尝试自己改改源码. 1.1 https://github.com/apache/activemq/r ...

  8. ActiveMQ笔记——技术点汇总

    目录 · Introduction to ActiveMQ · Installing ActiveMQ · Message-oriented middleware · JMS specificatio ...

  9. ActiveMq笔记3-AMQ高可用性理论

    单点的ActiveMQ作为企业应用无法满足高可用和集群的需求,所以ActiveMQ提供了master-slave.broker cluster等多种部署方式,但通过分析多种部署方式之后我认为需要将两种 ...

随机推荐

  1. gulp系列文章一 fis vs grunt vs gulp,为什么要是gulp呢?

    gulp是最近火起来的前端构建工具,大有赶超grunt之势,它和grunt这种构建工具比较像. grunt是写一个Gruntfile.js来写配置代码,gulp则是写一个gulpfile.js来写配置 ...

  2. 延迟对象$q和供应商配置config

    1.angular总的$q和jquery中的延迟对象很类似,用法也差不多 m1.controller('meng',['$scope','$q',function($scope,$q){ var df ...

  3. 【Docker 在 windows 10 / windows 8 下安装】

    步骤: 1. 下载: a.https://github.com/boot2docker/windows-installer/releases 下载一个 windows 客户端: 安装时建议勾选:Boo ...

  4. MVC 前台向后台传输数据

    今天,我们一起来学习下.MVC如何在前台给后台传输数据 (1)前台传输数据到后台 具体思路:前台拼凑json字符串,然后通过 get 或 post 方式,传递到后台 Action 方法中 我现在前台展 ...

  5. Android框架之AndroidAnnotations实战

    方案一: 下载 androidannotations-bundle-3.3.2.zip 方案二:   楼主选用开发环境:android studio 新建项目  修改app 下的build.gradl ...

  6. [转载]赖勇浩:推荐《Linux 多线程服务器端编程》

    推荐<Linux 多线程服务器端编程> 赖勇浩(http://laiyonghao.com) 最近,有一位朋友因为工作需要,需要从网游的客户端编程转向服务器端编程,找我推荐一本书.我推荐了 ...

  7. Oracle中执行存储过程call和exec区别

    Oracle中执行存储过程call和exec区别 在sqlplus中这两种方法都可以使用: exec pro_name(参数1..); call pro_name(参数1..); 区别: 1. 但是e ...

  8. 手势估计- Hand Pose Estimation

    http://blog.csdn.net/myarrow/article/details/51933651 1. 目前进展 1.1 相关资料      1)HANDS CVPR 2016      2 ...

  9. uploadify 后台动态传参数

    最近项目中用到上传控件,参数需要动态传参,经过查询总结了一下Uploadify 动态传参 jQuery(document).ready(function () { var ctrlid = getQu ...

  10. 【Mail】邮件的基础知识和原理

    电子邮件概念 电子邮件是-种用电子手段提供信息交换的通信方式,是互联网应用最广的服务.通过网络的电子邮件系统,用户可以以非常低廉的价格(不管发送到哪里,都只需负担网费).非常快速的方式(几秒钟之内可以 ...