NetMQ PUSH套接字在到达HWM时无限期阻塞

时间:2016-01-03 09:12:40

标签: zeromq netmq

我在.NET 4.5上使用NetMQ(Nuget 3.3.2.2),我有一个带有PUSH套接字的快速生成器进程,以及一个使用PULL套接字的慢速消费者进程。如果我发送足够的消息来命中发送HWM,则发送过程将无限期地阻塞该线程。

一些设计(生成器)代码说明了问题:

        using (var ctx = NetMQContext.Create())
        using (var pushSocket = ctx.CreatePushSocket())
        {
            pushSocket.Connect("tcp://127.0.0.1:42404");

            var template = GenerateMessageBody(i);
            for (int i = 1; i <= 100000; i++)
            {
                pushSocket.SendMoreFrame("SampleMessage").SendFrame(Messages.SerializeToByteArray(template));

                if (i % 1000 == 0)
                    Console.WriteLine("Sent " + i + " messages");
            }
            Console.WriteLine("All finished");
            Console.ReadKey();
        }

在我的配置中,这通常会报告它已经发送了大约5000或6000条消息,然后只是阻止。如果我将发送HWM设置为较大的值(或0),则它会按预期发送所有消息。

看起来它正在等待再次尝试之前接收另一个命令,这里:(SocketBase.TrySend)

        // Oops, we couldn't send the message. Wait for the next
        // command, process it and try to send the message again.
        // If timeout is reached in the meantime, return EAGAIN.
        while (true)
        {
            ProcessCommands(timeoutMillis, false);

从我在0MQ指南中读到的内容来看,阻塞完整的PUSH sockeet是正确的行为(并且是我希望它做的事情),但是我希望它能在消费者清除队列后恢复。

如果没有使用某种TrySend模式并自行处理该块,是否可以设置一些选项或者我可以使用其他设施让PUSH套接字尝试定期重新发送被阻止的消息?

0 个答案:

没有答案
相关问题