DotNetMQ-基于C#和.NET框架的开源消息队列系统
这是一位NB的土耳其开发人员基于C#和.NET框架,编写的开源消息队列系统DotNetMQ。DotNetMQ消息组件支持消息可靠传输、路由、负载均衡、服务器部署图(Server Graphs)等等。
企业级应用系统经常需要通过消息来进行沟通或集成,在Microsoft 平台,还有其他的类似解决方案,如MSMQ、BizTalk、sql Server Service Broker等等,这些产品或解决方案有各自的特点和适用场景。这里推荐的DotNetMQ消息系统,也是其适应的业务场景。
DotNetMQ 消息系统特性列表:
- Persistent or non-persistent messaging.
- Guaranteed delivery of persistent messages even in a system crash.
- Automatic and manual routing of messages in a custom machine graph.
- Supports multiple databases (MysqL,sqlite,and memory-based storage for now).
- Supports don’t store,direct send style messaging.
- Supports Request/Reply style messaging.
- Easy to use client library to communicate with the DotNetMQ Message Broker.
- Built-in framework to easily construct RMI services upon message queues.
- Supports delivering messages to ASP.NET Web Services.
- GUI-based management and monitoring tool.
- Easy to install,manage,and use.
- Written entirely in C# (using .NET Framework 3.5).
在多个Server 之间自动路由消息:
EntLib.com Team 随后会提供针对DotNetMQ 消息队列系统在.NET项目中更详细的中文使用范例。
DotNetMQ的具体介绍和源码下载,请访问如下链接:
DotNetMQ: A Complete Message Queue System for .NET
DotNetMQ-基于C#和.NET框架的开源消息队列系统 – 安装部署及消息发送接收范例
关于DotNetMQ 开源消息队列系统的介绍,可参考如下文章:
下面具体介绍如何安装、部署以及使用DotNetMQ 消息组件。
1. 先看看DotNetMQ 项目源码
DotNetMQ 项目是消息组件服务;MDSManager 项目消息组件的管理界面,用来配置系统中的客户端机器,如下图所示。
MDSCommonLib 项目是客户端系统需要引用的DLL程序集,使客户端系统可以和MDS 服务进行交互。
2. 部署DotNetMQ 服务
该服务编译的DLL程序集在如下目录 — DotNetMQ_Sources\DotNetMQ\bin\Debug
在CMD窗口中,在上述目录下,执行如下命令,安装部署 DotNetMQ 服务:
installutil dotnetmq.exe
看看安装好的DotNetMQ服务,并启动服务。
3. 注册和配置DotNetMQ 消息应用程序
在安装部署好DotNetMQ服务之后,开始运行MDSManager.exe 程序,添加和注册客户端应用程序,如下所示,添加Application1和Application2 应用程序。
如上图所示,添加好应用程序配置之后,可以到DotNetMQ_Sources\DotNetMQ\bin\Debug 目录下,查看MDSSettings.xml 配置文件:
@H_502_98@
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
MDSConfiguration
>
<
Settings
>
<
Setting
Key
=
"ThisServerName"
Value
=
"this_server"
/>
</
Settings
>
<
Servers
>
<
Server
IpAddress
=
"127.0.0.1"
Port
=
"10905"
Adjacents
=
""
/>
</
Servers
>
<
Applications
>
<
Application
/>
<
Application
/>
</
Applications
>
</
MDSConfiguration
>
|
4. 开发和运行客户端范例程序
在Visual studio 2010 开发工具下,编写2个简单的Console 应用程序:Application1和Application2。其中,Application1 用来发送消息;Application2 用来接收并显示消息。
在上述程序中,需要添加对 MDSCommonLib 程序集的引用,并且在代码中添加MDS.Client 命名空间的引用。
Application1 发送消息部分的代码如下:
@H_502_98@
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
MDS.Client;
namespace
Application1
{
class
Program
{
static
void
Main(
string
[] args)
{
var mdsClient =
new
MDSClient(
"Application1"
);
mdsClient.Connect();
while
(
true
)
{
var messageText = Console.ReadLine();
if
(
string
.IsNullOrEmpty(messageText) || messageText ==
"exit"
)
{
break
;
}
var message = mdsClient.CreateMessage();
message.DestinationApplicationName =
"Application2"
;
message.MessageData = Encoding.UTF8.GetBytes(messageText);
message.Send();
}
mdsClient.Disconnect();
}
}
}
|