Created
December 13, 2014 16:19
-
-
Save somdoron/0aeba2681bdf0d45e694 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void InProcWorkers() | |
{ | |
int count = 100; | |
int workers = 10; | |
using (NetMQContext context = NetMQContext.Create()) | |
{ | |
using (var response = context.CreateResponseSocket()) | |
{ | |
response.Bind("inproc://rep"); | |
Action action = () => | |
{ | |
using (var request = context.CreateRequestSocket()) | |
{ | |
request.Connect("inproc://rep"); | |
for (int i = 0; i < count; i++) | |
{ | |
request.Send(i.ToString()); | |
request.ReceiveString(); | |
} | |
} | |
}; | |
for (int i = 0; i < workers; i++) | |
{ | |
Task.Factory.StartNew(action); | |
} | |
for (int i = 0; i < workers*count; i++) | |
{ | |
string message = response.ReceiveString(); | |
Console.WriteLine(message); | |
response.Send(i.ToString()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment