├── .gitattributes
├── .gitignore
├── README.md
└── ZeroMQ
├── Model
├── Address.cs
├── Model.csproj
├── Person.cs
└── Properties
│ └── AssemblyInfo.cs
├── NetMQ_Pub
├── App.config
├── NetMQPub.cs
├── NetMQ_Pub.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── NetMQ_Sink
├── App.config
├── NetMQ_Sink.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── NetMQ_Sub
├── App.config
├── NetMQSub.cs
├── NetMQ_Sub.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── NetMQ_Ventilator
├── App.config
├── NetMQ_Ventilator.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── Ventilator.cs
└── packages.config
├── NetMQ_Worker
├── App.config
├── NetMQ_Worker.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── Worker.cs
└── packages.config
├── OMQ_Client
├── App.config
├── OMQ_Client.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── OMQ_Server
├── App.config
├── OMQ_Server.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── ZeroMQ.sln
└── packages
├── AsyncIO.0.1.17.0
└── lib
│ ├── net35
│ └── AsyncIO.dll
│ └── net40
│ └── AsyncIO.dll
├── NetMQ.3.3.2.2
└── lib
│ ├── net35
│ ├── NetMQ.XML
│ └── NetMQ.dll
│ └── net40
│ ├── NetMQ.XML
│ └── NetMQ.dll
├── Newtonsoft.Json.8.0.3
├── lib
│ ├── net20
│ │ ├── Newtonsoft.Json.dll
│ │ └── Newtonsoft.Json.xml
│ ├── net35
│ │ ├── Newtonsoft.Json.dll
│ │ └── Newtonsoft.Json.xml
│ ├── net40
│ │ ├── Newtonsoft.Json.dll
│ │ └── Newtonsoft.Json.xml
│ ├── net45
│ │ ├── Newtonsoft.Json.dll
│ │ └── Newtonsoft.Json.xml
│ ├── portable-net40+sl5+wp80+win8+wpa81
│ │ ├── Newtonsoft.Json.dll
│ │ └── Newtonsoft.Json.xml
│ └── portable-net45+wp80+win8+wpa81+dnxcore50
│ │ ├── Newtonsoft.Json.dll
│ │ └── Newtonsoft.Json.xml
└── tools
│ └── install.ps1
└── repositories.config
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore Windows thumbnails
2 | Thumbs.db
3 |
4 | # Ignore Visual Studio files
5 | *.obj
6 | *.exe
7 | *.pdb
8 | *.nupkg
9 | *.user
10 | *.aps
11 | *.pch
12 | *.vspscc
13 | *_i.c
14 | *_p.c
15 | *.ncb
16 | *.suo
17 | *.tlb
18 | *.tlh
19 | *.bak
20 | *.cache
21 | *.ilk
22 | *.log
23 | *.orig
24 | [Bb]in
25 | [Dd]ebug*/
26 | *.lib
27 | *.sbr
28 | obj/
29 | [Rr]elease*/
30 | _ReSharper*/
31 | *.DotSettings
32 | [Tt]est[Rr]esult*
33 |
34 | # Ignore MonoDevelop files
35 | *.userprefs
36 |
37 | # Ignore NUnit project files
38 | *.nunit
39 |
40 | # Ignore NuGet Packages
41 | /src/packages/
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #### [ZeroMQ系列 之NetMQ](http://www.cnblogs.com/liusc/p/5461038.html)####
2 | #### [一:zeromq简介](http://www.cnblogs.com/liusc/p/5461042.html) ####
3 | #### [二:NetMQ 请求响应模式 Request-Reply](http://www.cnblogs.com/liusc/p/5461055.html) ####
4 | #### [三:NetMQ 发布订阅模式 Publisher-Subscriber](http://www.cnblogs.com/liusc/p/5461060.html) ####
5 | #### [四:NetMQ 推拉模式 Push-Pull](http://www.cnblogs.com/liusc/p/5461184.html) ####
6 |
7 | # zeromq简介 #
8 | **`NetMQ` 是 `ZeroMQ`的C#移植版本。**
9 | **`NetMQ` 版本 3.3.2.2**
10 |
11 | ## 1:zeromq是什么 ##
12 | `NetMQ` (ZeroMQ to .Net),`ZMQ`号称史上最快中间件。
13 | 它对`socket`通信进行了封装,使得我们不需要写`socket`函数调用就能完成复杂的网络通信。
14 | 它跟`Socket`的区别是:普通的`socket`是端到端的(`1:1`的关系),而`ZMQ`却是可以`N:M`的关系,人们对`BSD`套接字的了解较多的是点对点的连接,点对点连接需要显式地建立连接、销毁连接、选择协议(TCP/UDP)和处理错误等,而`ZMQ`屏蔽了这些细节,让你的网络编程更为简单。
15 | 它是一个消息处理队列库,可在多个线程、内核和主机盒之间弹性伸缩。和一般意义上的消息队列产品不同的是,它没有消息队列服务器,而更像是一个网络通信库。从网络通信的角度看,它处于会话层之上,应用层之下,属于传输层。
16 | ## 2:zeromq的消息模型 ##
17 | `zeromq`将消息通信分为4种模型,分别是一对一结对模型(`Exclusive-Pair`)、请求回应模型(`Request-Reply`)、发布订阅模型(`Publish-Subscribe`)、推拉模型(`Push-Pull`)。这4种模型总结出了通用的网络通信模型,在实际中可以根据应用需要,组合其中的2种或多种模型来形成自己的解决方案。
18 |
19 | ### 2.1 一对一结对模型 Exclusive-Pair ###
20 | 最简单的`1:1`消息通信模型,用来支持传统的 `TCP socket `模型,主要用于进程内部线程间通信。可以认为是一个`TCP Connection`,但是`TCP Server`只能接受一个连接。采用了lock free实现,速度很快。数据可以双向流动,这点不同于后面的请求响应模型。(不推荐使用,没有例子)
21 | ### 2.2 请求回应模型 Request-Reply ###
22 | 由请求端发起请求,然后等待回应端应答。一个请求必须对应一个回应,从请求端的角度来看是发-收配对,从回应端的角度是收-发对。跟一对一结对模型的区别在于请求端可以是`1~N`个。
23 | 请求端和回应端都可以是`1:N`的模型。通常把`1`认为是`server`,`N`认为是`Client`。`ZeroMQ`可以很好的支持路由功能(实现路由功能的组件叫作`Device`),把`1:N`扩展为`N:M`(只需要加入若干路由节点)。从这个模型看,更底层的端点地址是对上层隐藏的。每个请求都隐含有回应地址,而应用则不关心它。通常把该模型主要用于远程调用及任务分配等。
24 | [(NetMQ请求响应C#调用案例)](http://www.cnblogs.com/liusc/p/5461055.html "NetMQ 请求响应模式 Request-Reply" )
25 |
26 |
27 | ### 2.3 发布订阅模型 Publisher-Subscriber ###
28 | 发布端单向分发数据,且不关心是否把全部信息发送给订阅端。如果发布端开始发布信息时,订阅端尚未连接上来,则这些信息会被直接丢弃。订阅端未连接导致信息丢失的问题,可以通过与请求回应模型组合来解决。订阅端只负责接收,而不能反馈,且在订阅端消费速度慢于发布端的情况下,会在订阅端堆积数据。该模型主要用于数据分发。天气预报、微博明星粉丝可以应用这种经典模型。 [(NetMQ发布订阅模式C#调用案例)](http://www.cnblogs.com/liusc/p/5461060.html "NetMQ 发布订阅模式 Publisher-Subscriber ")
29 | ### 2.4 推拉模型 Push-Pull ###
30 | Server端作为Push端,而Client端作为Pull端,如果有多个Client端同时连接到Server端,则Server端会在内部做一个负载均衡,采用平均分配的算法,将所有消息均衡发布到Client端上。与发布订阅模型相比,推拉模型在没有消费者的情况下,发布的消息不会被消耗掉;在消费者能力不够的情况下,能够提供多消费者并行消费解决方案。该模型主要用于多任务并行。
31 | [(NetMQ推拉模式C#调用案例)](http://www.cnblogs.com/liusc/p/5461184.html "NetMQ 推拉模式 Push-Pull")
32 |
33 | ## 3:zeromq的优势 ##
34 | - TCP:ZeroMQ基于消息,消息模式,而非字节流。
35 | - XMPP:ZeroMQ更简单、快速、更底层。Jabber可建在ZeroMQ之上。
36 | - AMQP:完成相同的工作,ZeroMQ要快100倍,而且不需要代理(规范更简洁——少278页)
37 | - IPC:ZeroMQ可以跨多个主机盒,而非单台机器。
38 | - CORBA:ZeroMQ不会将复杂到恐怖的消息格式强加于你。
39 | - RPC:ZeroMQ完全是异步的,你可以随时增加/删除参与者。
40 | - RFC 1149:ZeroMQ比它快多了!
41 | - 29west LBM:ZeroMQ是自由软件!
42 | - IBM低延迟:ZeroMQ是自由软件!
43 | - Tibco:仍然是自由软件!
--------------------------------------------------------------------------------
/ZeroMQ/Model/Address.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Model
7 | {
8 | public class Address
9 | {
10 | public string Line1 { get; set; }
11 | public string Line2 { get; set; }
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ZeroMQ/Model/Model.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {B679D836-0357-4A67-AF84-3AF3B1CDE49F}
8 | Library
9 | Properties
10 | Model
11 | Model
12 | v4.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
54 |
--------------------------------------------------------------------------------
/ZeroMQ/Model/Person.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Model
8 | {
9 | public class Person
10 | {
11 | public int Id { get; set; }
12 | public string Name { get; set; }
13 | public DateTime BirthDay { get; set; }
14 | public Address Address { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ZeroMQ/Model/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("Model")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("Model")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("12ac0622-f8e5-4308-85cd-d74bfb3476fa")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Pub/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Pub/NetMQPub.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using System.Threading;
8 | using NetMQ;
9 |
10 | namespace NetMQ_Pub
11 | {
12 | public class NetMQPub
13 | {
14 | readonly static ManualResetEvent _terminateEvent = new ManualResetEvent(false);
15 | ///
16 | /// NetMQ 发布端
17 | ///
18 | public static void Start()
19 | {
20 | string[] weathers = new string[6] { "晴朗", "多云", "阴天", "霾", "雨", "雪" };
21 |
22 | Console.WriteLine("发布多个地区天气预报:");
23 |
24 | using (NetMQContext context = NetMQContext.Create())
25 | {
26 | using (var publisher = context.CreatePublisherSocket())
27 | {
28 | publisher.Bind("tcp://127.0.0.1:5556");
29 |
30 | var rng = new Random();
31 | string msg;
32 | int sleeptime = 1000;//1秒
33 |
34 | ///指定发布的时间间隔,1秒
35 | while (_terminateEvent.WaitOne(1000) == false)
36 | {
37 | //随机生成天气数据
38 | int zipcode = rng.Next(0, 99);
39 | int temperature = rng.Next(-50, 50);
40 | int weatherId = rng.Next(0, 5);
41 |
42 | msg = string.Format("{0} {1} {2}", zipcode, temperature, weathers[weatherId]);
43 | publisher.SendFrame(msg);
44 |
45 | Console.WriteLine(msg);
46 | Thread.Sleep(sleeptime);
47 | }
48 | }
49 | }
50 | }
51 |
52 | private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
53 | {
54 | Console.WriteLine("exit……");
55 | _terminateEvent.Set();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Pub/NetMQ_Pub.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {AA47F7F6-D7B6-4885-A08B-EFEA0B7C4919}
8 | Exe
9 | Properties
10 | NetMQ_Pub
11 | NetMQ_Pub
12 | v4.5
13 | 512
14 | true
15 |
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 | ..\packages\AsyncIO.0.1.17.0\lib\net40\AsyncIO.dll
39 | True
40 |
41 |
42 | ..\packages\NetMQ.3.3.2.2\lib\net40\NetMQ.dll
43 | True
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
71 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Pub/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetMQ_Pub
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | NetMQPub.Start();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Pub/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("NetMQ_Pub")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("NetMQ_Pub")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | //将 ComVisible 设置为 false 将使此程序集中的类型
18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("aa47f7f6-d7b6-4885-a08b-efea0b7c4919")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Pub/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sink/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sink/NetMQ_Sink.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {CB9DDD85-D0E7-49FB-B28A-98160760DCE4}
8 | Exe
9 | Properties
10 | NetMQ_Sink
11 | NetMQ_Sink
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | ..\packages\AsyncIO.0.1.17.0\lib\net40\AsyncIO.dll
37 | True
38 |
39 |
40 | ..\packages\NetMQ.3.3.2.2\lib\net40\NetMQ.dll
41 | True
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
67 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sink/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using NetMQ;
8 | using System.Diagnostics;
9 |
10 | namespace NetMQ_Sink
11 | {
12 | class Program
13 | {
14 | static void Main(string[] args)
15 | {
16 | // Task Sink
17 | //Bind PULL socket to tcp://127.0.0.1:5558
18 | //Collects results from workers via that socket
19 | Console.WriteLine("=====SINK=====");
20 |
21 | using (NetMQContext context = NetMQContext.Create())
22 | {
23 | //socket to receive messages on
24 | using (var receiver = context.CreatePullSocket())
25 | {
26 | receiver.Bind("tcp://localhost:5558");
27 |
28 | //wait for start of batch (see Ventilator.csproj Program.cs)
29 | var startOfBatchTrigger = receiver.ReceiveFrameString();
30 | Console.WriteLine("Seen start of batch");
31 |
32 | //Start our clock now
33 | Stopwatch watch = new Stopwatch();
34 | watch.Start();
35 |
36 | for (int taskNumber = 0; taskNumber < 10000; taskNumber++)
37 | {
38 | var workerDoneTrigger = receiver.ReceiveFrameString();
39 | Console.WriteLine(workerDoneTrigger);
40 | }
41 |
42 | watch.Stop();
43 |
44 | Console.WriteLine();
45 | Console.WriteLine("Total elapsed time {0} msec", watch.ElapsedMilliseconds);
46 | Console.ReadLine();
47 | }
48 |
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sink/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("NetMQ_Sink")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("NetMQ_Sink")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("dcfd1ba6-84aa-4624-9565-8b45f7bbb5fd")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sink/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sub/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sub/NetMQSub.cs:
--------------------------------------------------------------------------------
1 | using NetMQ;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Globalization;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace NetMQ_Sub
10 | {
11 | public class NetMQSub
12 | {
13 | public delegate void GetDataHandler(string message);
14 | public static event GetDataHandler OnGetData;
15 | ///
16 | /// NetMQ 订阅端
17 | ///
18 | public static void Start()
19 | {
20 | var rng = new Random();
21 | int zipcode = rng.Next(0, 99);
22 | Console.WriteLine("接收本地天气预报{0}……", zipcode);
23 |
24 | OnGetData += new GetDataHandler(ProcessData);
25 |
26 | using (var context = NetMQContext.Create())
27 | {
28 | using (var subscriber = context.CreateSubscriberSocket())
29 | {
30 | subscriber.Connect("tcp://127.0.0.1:5556");
31 | subscriber.Subscribe(zipcode.ToString(CultureInfo.InvariantCulture));
32 | //subscriber.Subscribe("");
33 |
34 | while (true)
35 | {
36 | string results = subscriber.ReceiveFrameString(Encoding.UTF8);
37 | Console.WriteLine(".");
38 |
39 | string[] split = results.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
40 |
41 | int zip = int.Parse(split[0]);
42 | if (zip == zipcode)
43 | {
44 | OnGetData(results);
45 | }
46 | }
47 |
48 | }
49 | }
50 | }
51 |
52 | private static void ProcessData(string message)
53 | {
54 | Console.WriteLine("天气情况:" + message);
55 | }
56 |
57 |
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sub/NetMQ_Sub.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {A596928E-0724-4EE3-A429-CA545BB27633}
8 | Exe
9 | Properties
10 | NetMQ_Sub
11 | NetMQ_Sub
12 | v4.5
13 | 512
14 | true
15 |
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 | ..\packages\AsyncIO.0.1.17.0\lib\net40\AsyncIO.dll
39 | True
40 |
41 |
42 | ..\packages\NetMQ.3.3.2.2\lib\net40\NetMQ.dll
43 | True
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
71 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sub/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetMQ_Sub
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | NetMQSub.Start();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sub/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("NetMQ_Sub")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("NetMQ_Sub")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | //将 ComVisible 设置为 false 将使此程序集中的类型
18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("a596928e-0724-4ee3-a429-ca545bb27633")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Sub/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Ventilator/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Ventilator/NetMQ_Ventilator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {75DBE113-7CFF-4F08-B702-D4B26B468F5A}
8 | Exe
9 | Properties
10 | NetMQ_Ventilator
11 | NetMQ_Ventilator
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | ..\packages\AsyncIO.0.1.17.0\lib\net40\AsyncIO.dll
37 | True
38 |
39 |
40 | ..\packages\NetMQ.3.3.2.2\lib\net40\NetMQ.dll
41 | True
42 |
43 |
44 | ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll
45 | True
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | {b679d836-0357-4a67-af84-3af3b1cde49f}
69 | Model
70 |
71 |
72 |
73 |
80 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Ventilator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using NetMQ;
8 |
9 | namespace NetMQ_Ventilator
10 | {
11 | class Program
12 | {
13 | public static void Main(string[] args)
14 | {
15 | //Task Ventilator
16 | //Binds PUSH socket to tcp://localhost:5557
17 | //Sends batch of tasks to workers via that socket
18 | Console.WriteLine("=========VENTILATOR===========");
19 |
20 | Console.WriteLine("Press enter when worker are ready");
21 | Console.ReadLine();
22 |
23 | //the first message it "0" and signals start of batch
24 | //see the Sink.csproj Program.cs file for where this is used
25 | Console.WriteLine("Sending start of batch to Sink");
26 |
27 | var ventilator = new Ventilator();
28 | ventilator.Run();
29 |
30 | Console.WriteLine("Press Enter to quit");
31 | Console.ReadLine();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Ventilator/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("NetMQ_Ventilator")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("NetMQ_Ventilator")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("8babbaa0-a84b-408e-a875-97907bff8071")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Ventilator/Ventilator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using NetMQ;
8 | using Model;
9 | using Newtonsoft.Json;
10 | using System.IO;
11 |
12 | namespace NetMQ_Ventilator
13 | {
14 | sealed class Ventilator
15 | {
16 | public void Run()
17 | {
18 | Task.Run(() =>
19 | {
20 | using (var context = NetMQContext.Create())
21 | using (var sender = context.CreatePushSocket())
22 | using (var sink = context.CreatePushSocket())
23 | {
24 | sender.Bind("tcp://*:5557");
25 | sink.Connect("tcp://127.0.0.1:5558");
26 | sink.SendFrame("0");
27 |
28 | Console.WriteLine("Sending tasks to workers");
29 | //RuntimeTypeModel.Default.MetadataTimeoutMilliseconds = 300000;
30 |
31 | //send 100 tasks(workload for tasks,is just some random sleep time that
32 | //the workers can perofrm, in real life each work would do more than sleep
33 |
34 | for (int taskNumber = 0; taskNumber < 10000; taskNumber++)
35 | {
36 | Console.WriteLine("Workload:{0}", taskNumber);
37 | var person = new Person
38 | {
39 | Id = taskNumber,
40 | Name = "First",
41 | BirthDay = DateTime.Parse("1981-11-15"),
42 | Address = new Address { Line1 = "line1", Line2 = "line2" }
43 | };
44 |
45 | using (var sm = new MemoryStream())
46 | {
47 | string s = JsonConvert.SerializeObject(person);
48 |
49 | sender.SendFrame(s);
50 | }
51 | }
52 | }
53 | });
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Ventilator/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Worker/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Worker/NetMQ_Worker.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {C5AB99E2-EE6C-45CA-8D67-26C6DEB87596}
8 | Exe
9 | Properties
10 | NetMQ_Worker
11 | NetMQ_Worker
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | ..\packages\AsyncIO.0.1.17.0\lib\net40\AsyncIO.dll
37 | True
38 |
39 |
40 | ..\packages\NetMQ.3.3.2.2\lib\net40\NetMQ.dll
41 | True
42 |
43 |
44 | ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll
45 | True
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | {b679d836-0357-4a67-af84-3af3b1cde49f}
67 | Model
68 |
69 |
70 |
71 |
78 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Worker/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetMQ_Worker
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | //Task Worker
14 | //Connects PULL socket to tcp://localhost:5557
15 | //collects workload for socket from Ventilator via that socket
16 | //collects PUSH socket to tcp://localhost:5558
17 | //Sends results to Sink via that socket
18 |
19 | Console.WriteLine("=====WORKER=====");
20 |
21 | ////Task 方式多线程
22 | //foreach (Worker client in Enumerable.Range(0, 1000).Select(x => new Worker()))
23 | //{
24 | // client.Run();
25 | //}
26 |
27 | //多核计算方式多线程
28 | var actList = Enumerable.Range(0, 50).Select(x => new Worker()).Select(client => (Action)(client.Run)).ToList();
29 | var paraOption = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
30 | Parallel.Invoke(paraOption, actList.ToArray());
31 |
32 | Console.ReadLine();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Worker/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("NetMQ_Worker")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("NetMQ_Worker")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("cc03a5a8-0282-4af7-b8ba-667a9f30055e")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Worker/Worker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using NetMQ;
8 | using Model;
9 | using Newtonsoft.Json;
10 | using Newtonsoft.Json.Linq;
11 |
12 | namespace NetMQ_Worker
13 | {
14 | sealed class Worker
15 | {
16 | public void Run()
17 | {
18 | Task.Run(() =>
19 | {
20 | using (NetMQContext context = NetMQContext.Create())
21 | {
22 | //socket to receive messages on
23 | using (var receiver = context.CreatePullSocket())
24 | {
25 | receiver.Connect("tcp://127.0.0.1:5557");
26 |
27 | //socket to send messages on
28 | using (var sender = context.CreatePushSocket())
29 | {
30 | sender.Connect("tcp://127.0.0.1:5558");
31 |
32 | //process tasks forever
33 | while (true)
34 | {
35 | //workload from the vetilator is a simple delay
36 | //to simulate some work being done, see
37 | //Ventilator.csproj Program.cs for the workload sent
38 | //In real life some more meaningful work would be done
39 |
40 | string workload = receiver.ReceiveString();
41 |
42 | var person = JsonConvert.DeserializeObject(workload);
43 |
44 | //JArray ja = JArray.Parse(workload);
45 |
46 | Console.WriteLine("Person {Id:" + person.Id + ",Name:" + person.Name + ",BirthDay:" +
47 | person.BirthDay + ",Address:{Line1:" + person.Address.Line1 +
48 | ",Line2:" + person.Address.Line2 + "}}");
49 | Console.WriteLine("Sending to Sink:" + person.Id);
50 | sender.SendFrame(person.Id + "");
51 | //sender.SendFrame("liuwq" + DateTime.Now);
52 | }
53 |
54 | //simulate some work being done
55 | //Thread.Sleep(int.Parse(workload));
56 | }
57 | }
58 | }
59 | });
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/ZeroMQ/NetMQ_Worker/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Client/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Client/OMQ_Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {4ADC4597-BC52-4F83-BD32-A7FD4E15CF5F}
8 | Exe
9 | Properties
10 | OMQ_Client
11 | OMQ_Client
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | ..\packages\AsyncIO.0.1.17.0\lib\net40\AsyncIO.dll
37 | True
38 |
39 |
40 | ..\packages\NetMQ.3.3.2.2\lib\net40\NetMQ.dll
41 | True
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
67 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Client/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using NetMQ;
8 |
9 | namespace OMQ_Client
10 | {
11 | class Program
12 | {
13 | static void Main(string[] args)
14 | {
15 | using (NetMQContext context = NetMQContext.Create())
16 | {
17 | Client(context);
18 | }
19 | }
20 |
21 | private static void Client(NetMQContext context)
22 | {
23 | using (NetMQSocket clientSocket = context.CreateRequestSocket())
24 | {
25 | Random rd = new Random();
26 | int num = rd.Next(0, 100);
27 | clientSocket.Connect("tcp://127.0.0.1:5555");
28 | while (true)
29 | {
30 | Console.WriteLine(num + ",Please enter your message:");
31 | string message = Console.ReadLine();
32 | clientSocket.SendFrame(num + ":" + message);
33 |
34 | string answer = clientSocket.ReceiveFrameString();
35 |
36 | Console.WriteLine("Answer from server:{0}", answer);
37 |
38 | if (message == "exit")
39 | {
40 | break;
41 | }
42 | }
43 | }
44 |
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Client/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("OMQ_Client")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("OMQ_Client")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("4adc4597-bc52-4f83-bd32-a7fd4e15cf5f")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Client/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Server/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Server/OMQ_Server.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {5D7EA24C-6CB9-45EF-A0B1-BB8C486ED148}
8 | Exe
9 | Properties
10 | OMQ_Server
11 | OMQ_Server
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 | ..\packages\AsyncIO.0.1.17.0\lib\net40\AsyncIO.dll
37 | True
38 |
39 |
40 | ..\packages\NetMQ.3.3.2.2\lib\net40\NetMQ.dll
41 | True
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
67 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Server/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using NetMQ;
8 |
9 | namespace OMQ_Server
10 | {
11 | class Program
12 | {
13 | static void Main(string[] args)
14 | {
15 | using (NetMQContext context = NetMQContext.Create())
16 | {
17 | Server(context);
18 | }
19 | }
20 |
21 | private static void Server(NetMQContext context)
22 | {
23 | using (NetMQSocket serverSocket = context.CreateResponseSocket())
24 | {
25 | serverSocket.Bind("tcp://127.0.0.1:5555");
26 | while (true)
27 | {
28 | string message1 = serverSocket.ReceiveFrameString();
29 |
30 | Console.WriteLine("Receive message :\r\n{0}\r\n", message1);
31 |
32 | string[] msg = message1.Split(':');
33 | string message = msg[1];
34 |
35 |
36 | #region 根据接收到的消息,返回不同的信息
37 | if (message == "Hello")
38 | {
39 | serverSocket.SendFrame("World");
40 | }
41 | else if (message == "ni hao ")
42 | {
43 | serverSocket.SendFrame("你好!");
44 | }
45 | else if (message == "hi")
46 | {
47 | serverSocket.SendFrame("HI");
48 | }
49 | else
50 | {
51 | serverSocket.SendFrame(message);
52 | }
53 | #endregion
54 |
55 |
56 |
57 | if (message == "exit")
58 | {
59 | break;
60 | }
61 | }
62 | }
63 |
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Server/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("OMQ_Server")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("OMQ_Server")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("5d7ea24c-6cb9-45ef-a0b1-bb8c486ed148")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ZeroMQ/OMQ_Server/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/ZeroMQ/ZeroMQ.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OMQ_Client", "OMQ_Client\OMQ_Client.csproj", "{4ADC4597-BC52-4F83-BD32-A7FD4E15CF5F}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OMQ_Server", "OMQ_Server\OMQ_Server.csproj", "{5D7EA24C-6CB9-45EF-A0B1-BB8C486ED148}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMQ_Pub", "NetMQ_Pub\NetMQ_Pub.csproj", "{AA47F7F6-D7B6-4885-A08B-EFEA0B7C4919}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMQ_Sub", "NetMQ_Sub\NetMQ_Sub.csproj", "{A596928E-0724-4EE3-A429-CA545BB27633}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMQ_Ventilator", "NetMQ_Ventilator\NetMQ_Ventilator.csproj", "{75DBE113-7CFF-4F08-B702-D4B26B468F5A}"
15 | EndProject
16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMQ_Worker", "NetMQ_Worker\NetMQ_Worker.csproj", "{C5AB99E2-EE6C-45CA-8D67-26C6DEB87596}"
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMQ_Sink", "NetMQ_Sink\NetMQ_Sink.csproj", "{CB9DDD85-D0E7-49FB-B28A-98160760DCE4}"
19 | EndProject
20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{B679D836-0357-4A67-AF84-3AF3B1CDE49F}"
21 | EndProject
22 | Global
23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
24 | Debug|Any CPU = Debug|Any CPU
25 | Release|Any CPU = Release|Any CPU
26 | EndGlobalSection
27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
28 | {4ADC4597-BC52-4F83-BD32-A7FD4E15CF5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {4ADC4597-BC52-4F83-BD32-A7FD4E15CF5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {4ADC4597-BC52-4F83-BD32-A7FD4E15CF5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {4ADC4597-BC52-4F83-BD32-A7FD4E15CF5F}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {5D7EA24C-6CB9-45EF-A0B1-BB8C486ED148}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {5D7EA24C-6CB9-45EF-A0B1-BB8C486ED148}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {5D7EA24C-6CB9-45EF-A0B1-BB8C486ED148}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {5D7EA24C-6CB9-45EF-A0B1-BB8C486ED148}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {AA47F7F6-D7B6-4885-A08B-EFEA0B7C4919}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {AA47F7F6-D7B6-4885-A08B-EFEA0B7C4919}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {AA47F7F6-D7B6-4885-A08B-EFEA0B7C4919}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {AA47F7F6-D7B6-4885-A08B-EFEA0B7C4919}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {A596928E-0724-4EE3-A429-CA545BB27633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {A596928E-0724-4EE3-A429-CA545BB27633}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {A596928E-0724-4EE3-A429-CA545BB27633}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {A596928E-0724-4EE3-A429-CA545BB27633}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {75DBE113-7CFF-4F08-B702-D4B26B468F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {75DBE113-7CFF-4F08-B702-D4B26B468F5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {75DBE113-7CFF-4F08-B702-D4B26B468F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {75DBE113-7CFF-4F08-B702-D4B26B468F5A}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {C5AB99E2-EE6C-45CA-8D67-26C6DEB87596}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {C5AB99E2-EE6C-45CA-8D67-26C6DEB87596}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {C5AB99E2-EE6C-45CA-8D67-26C6DEB87596}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {C5AB99E2-EE6C-45CA-8D67-26C6DEB87596}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {CB9DDD85-D0E7-49FB-B28A-98160760DCE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {CB9DDD85-D0E7-49FB-B28A-98160760DCE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {CB9DDD85-D0E7-49FB-B28A-98160760DCE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {CB9DDD85-D0E7-49FB-B28A-98160760DCE4}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {B679D836-0357-4A67-AF84-3AF3B1CDE49F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57 | {B679D836-0357-4A67-AF84-3AF3B1CDE49F}.Debug|Any CPU.Build.0 = Debug|Any CPU
58 | {B679D836-0357-4A67-AF84-3AF3B1CDE49F}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {B679D836-0357-4A67-AF84-3AF3B1CDE49F}.Release|Any CPU.Build.0 = Release|Any CPU
60 | EndGlobalSection
61 | GlobalSection(SolutionProperties) = preSolution
62 | HideSolutionNode = FALSE
63 | EndGlobalSection
64 | EndGlobal
65 |
--------------------------------------------------------------------------------
/ZeroMQ/packages/AsyncIO.0.1.17.0/lib/net35/AsyncIO.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/AsyncIO.0.1.17.0/lib/net35/AsyncIO.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/AsyncIO.0.1.17.0/lib/net40/AsyncIO.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/AsyncIO.0.1.17.0/lib/net40/AsyncIO.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/NetMQ.3.3.2.2/lib/net35/NetMQ.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/NetMQ.3.3.2.2/lib/net35/NetMQ.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/NetMQ.3.3.2.2/lib/net40/NetMQ.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/NetMQ.3.3.2.2/lib/net40/NetMQ.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/net20/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/net20/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/net35/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/net35/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/net40/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/net40/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/net45/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/net45/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuwqGit/ZeroMQ/a5f5bd1c344c8efdc5eec8a9a4f882b9fd1c7d05/ZeroMQ/packages/Newtonsoft.Json.8.0.3/lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/ZeroMQ/packages/Newtonsoft.Json.8.0.3/tools/install.ps1:
--------------------------------------------------------------------------------
1 | param($installPath, $toolsPath, $package, $project)
2 |
3 | # open json.net splash page on package install
4 | # don't open if json.net is installed as a dependency
5 |
6 | try
7 | {
8 | $url = "http://www.newtonsoft.com/json/install?version=" + $package.Version
9 | $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
10 |
11 | if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
12 | {
13 | # user is installing from VS NuGet console
14 | # get reference to the window, the console host and the input history
15 | # show webpage if "install-package newtonsoft.json" was last input
16 |
17 | $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
18 |
19 | $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
20 | [System.Reflection.BindingFlags]::NonPublic)
21 |
22 | $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
23 | if ($prop -eq $null) { return }
24 |
25 | $hostInfo = $prop.GetValue($consoleWindow)
26 | if ($hostInfo -eq $null) { return }
27 |
28 | $history = $hostInfo.WpfConsole.InputHistory.History
29 |
30 | $lastCommand = $history | select -last 1
31 |
32 | if ($lastCommand)
33 | {
34 | $lastCommand = $lastCommand.Trim().ToLower()
35 | if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))
36 | {
37 | $dte2.ItemOperations.Navigate($url) | Out-Null
38 | }
39 | }
40 | }
41 | else
42 | {
43 | # user is installing from VS NuGet dialog
44 | # get reference to the window, then smart output console provider
45 | # show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation
46 |
47 | $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
48 | [System.Reflection.BindingFlags]::NonPublic)
49 |
50 | $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
51 | [System.Reflection.BindingFlags]::NonPublic)
52 |
53 | if ($instanceField -eq $null -or $consoleField -eq $null) { return }
54 |
55 | $instance = $instanceField.GetValue($null)
56 |
57 | if ($instance -eq $null) { return }
58 |
59 | $consoleProvider = $consoleField.GetValue($instance)
60 | if ($consoleProvider -eq $null) { return }
61 |
62 | $console = $consoleProvider.CreateOutputConsole($false)
63 |
64 | $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
65 | [System.Reflection.BindingFlags]::NonPublic)
66 | if ($messagesField -eq $null) { return }
67 |
68 | $messages = $messagesField.GetValue($console)
69 | if ($messages -eq $null) { return }
70 |
71 | $operations = $messages -split "=============================="
72 |
73 | $lastOperation = $operations | select -last 1
74 |
75 | if ($lastOperation)
76 | {
77 | $lastOperation = $lastOperation.ToLower()
78 |
79 | $lines = $lastOperation -split "`r`n"
80 |
81 | $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1
82 |
83 | if ($installMatch)
84 | {
85 | $dte2.ItemOperations.Navigate($url) | Out-Null
86 | }
87 | }
88 | }
89 | }
90 | catch
91 | {
92 | try
93 | {
94 | $pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")
95 |
96 | $selection = $pmPane.TextDocument.Selection
97 | $selection.StartOfDocument($false)
98 | $selection.EndOfDocument($true)
99 |
100 | if ($selection.Text.StartsWith("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version + "'"))
101 | {
102 | # don't show on upgrade
103 | if (!$selection.Text.Contains("Removed package"))
104 | {
105 | $dte2.ItemOperations.Navigate($url) | Out-Null
106 | }
107 | }
108 | }
109 | catch
110 | {
111 | # stop potential errors from bubbling up
112 | # worst case the splash page won't open
113 | }
114 | }
115 |
116 | # still yolo
--------------------------------------------------------------------------------
/ZeroMQ/packages/repositories.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------