Open mainxx opened 3 years ago
This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.
I just ran into the exact same problem so it seems that they haven't fixed their docs. The code examples they give are slightly wrong. In the Ventilator program, it declares the sink as a Pull Socket which it tries to connect to and then send a frame, which causes this exception. The sink itself is a Pull socket which can only receive, and when the worker sends a message to the sink it uses a Push socket, so clearly the sink in Ventilator should also be a Push socket.
Just change part where it says: var sink = new PullSocket(">tcp://localhost:5558")
to var sink = new PushSocket(">tcp://localhost:5558")
and then it will work.
I might also make a pull request in NetMQ to update the docs so the code example actually works.
The Ventilator code should look like this:
using System;
using NetMQ;
using NetMQ.Sockets;
namespace Ventilator
{
public class Program
{
public static void Main(string[] args)
{
// Task Ventilator
// Binds PUSH socket to tcp://localhost:5557
// Connects sink PUSH socket to tcp://localhost:5558
// Sends batch of tasks to workers via that socket
Console.WriteLine("====== VENTILATOR ======");
using (var sender = new PushSocket("@tcp://*:5557"))
using (var sink = new PushSocket(">tcp://localhost:5558"))
{
Console.WriteLine("Press enter when worker are ready");
Console.ReadLine();
//the first message it "0" and signals start of batch
//see the Sink.csproj Program.cs file for where this is used
Console.WriteLine("Sending start of batch to Sink");
sink.SendFrame("0");
Console.WriteLine("Sending tasks to workers");
//initialise random number generator
Random rand = new Random(0);
//expected costs in Ms
int totalMs = 0;
//send 100 tasks (workload for tasks, is just some random sleep time that
//the workers can perform, in real life each work would do more than sleep
for (int taskNumber = 0; taskNumber < 100; taskNumber++)
{
//Random workload from 1 to 100 msec
int workload = rand.Next(0, 100);
totalMs += workload;
Console.WriteLine("Workload : {0}", workload);
sender.SendFrame(workload.ToString());
}
Console.WriteLine("Total expected cost : {0} msec", totalMs);
Console.WriteLine("Press Enter to quit");
Console.ReadLine();
}
}
}
}
So I just checked the docs in the NetMQ repo, and the code example for Ventilator in push-pull.md is the same as the one that I wrote. So it seems that was a mistake in the docs which they already fixed, but it must have not been updated on the readthedocs website.
Environment
Expected behaviour
run the example : https://netmq.readthedocs.io/en/latest/push-pull/
Actual behaviour
System.NotSupportedException HResult=0x80131515 Message=Pull socket doesn't support sending Source=NetMQ StackTrace: at NetMQ.Sockets.PullSocket.TrySend(Msg& msg, TimeSpan timeout, Boolean more) at NetMQ.OutgoingSocketExtensions.Send(IOutgoingSocket socket, Msg& msg, Boolean more) at NetMQ.OutgoingSocketExtensions.SendFrame(IOutgoingSocket socket, String message, Boolean more) at Ventilator.Program.Main(String[] args) in G:\VS_Repos\NetMQPushPullDemo\NetMQPushPullDemo\Ventilator\Program.cs:line 23
Steps to reproduce the behaviour
Ventilator
Sink
Worker