ZeroMQ是一個輕量級的消息內核,它是對標準socket接口的擴展。它提供了一種異步消息隊列,多消息模式,消息過濾(訂閱),對多種傳輸協議的無縫訪問。git
NetMQ 也是一個社區開源項目,網站在Github上 https://github.com/zeromq/netmq, 能夠經過Nuget包獲取http://nuget.org/packages/NetMQ。github
Ø 是一個併發框架.
Ø 支持經過進程內(Inproc),進程間(IPC), TCP, 和多播來傳遞消息.
Ø 支持多對多的列表、發佈/訂閱、管道和接收/回覆鏈接.
Ø 支持異步.併發
C# 客戶端服務端框架
Server.cs異步
public static void Main (string[] args) { using (NetMQContext context = NetMQContext.Create()) { Server(context); } } static void Server(NetMQContext context) { using (NetMQSocket serverSocket = context.CreateResponseSocket()) { serverSocket.Bind("tcp://*:5555"); while (true) { string message = serverSocket.ReceiveString(); Console.WriteLine("Receive message {0}", message); serverSocket.Send("World"); if (message == "exit") { break; } } } }
Client.cs
public static void Main (string[] args) { using (NetMQContext context = NetMQContext.Create()) { Client(context); } } static void Client(NetMQContext context) { using (NetMQSocket clientSocket = context.CreateRequestSocket()) { clientSocket.Connect("tcp://127.0.0.1:5555"); while (true) { Console.WriteLine("Please enter your message:"); string message = Console.ReadLine(); clientSocket.Send(message); string answer = clientSocket.ReceiveString(); Console.WriteLine("Answer from server: {0}", answer); if (message == "exit") { break; } } } }
NetMQ也支持Mono,下面是在Mono上的運行:
ZeroMQ研究與應用分析