Skip to content

Instantly share code, notes, and snippets.

@somdoron
Created December 13, 2014 16:19
Show Gist options
  • Save somdoron/0aeba2681bdf0d45e694 to your computer and use it in GitHub Desktop.
Save somdoron/0aeba2681bdf0d45e694 to your computer and use it in GitHub Desktop.
[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