1

I am using ZMQ for our project and wrote a factory that creates ZMQ Clients based on type of the message required. However, an issue I find is that, sometimes TrySendFrame returns false and most of the times it returns true. Any way this can be corrected?

The data remains same, the code remains same, address and everything remains same but occasionally it returns false from TrySendFrame.

I could not identify why it is failing. After using SendFrame instead of using TrySendFrame it gets blocked forever in some cases.

public ZmqPushClient(string address, bool isByteData = false) : base(address, isByteData)
            {
                if (Address.Contains("*"))
                {
                    Address = "@" + Address;
                    _pushSocket = new PushSocket(Address);
                }
                else
                {
                    _pushSocket = new PushSocket(Address);
                }
            }

public bool Push(string message)
            {
                lock (_locker)
                {
                    TimeSpan timeout = TimeSpan.FromMilliseconds(1000);
                    _logger.Debug("Pushing : " + message);
                    bool success = _pushSocket.TrySendFrame(timeout, message);
                    if (success)
                    {
                        _logger.Info("Success : " + success);
                    }
                    else
                    {
                        _logger.Error("Could not push to URL  : " + Address);
                    }
                    return success;
                }
            }

I expect the messages to be sent. At certain times it works perfectly fine, but sometimes I see error in logs which is a problem as a failed send has a good impact on my application.

undefined
  • 142
  • 10

1 Answers1

0

Q : Any way this can be corrected?

Sure, use a proper error-handling strategy for cases, when a PUSH-socket Archetype may legally get and legally gets into a blocking-state. Avoiding any blocking state is an alpha & omega in designing smart and efficiently running .

Your actual language-binding tools will serve you either the non-blocking- and blocking-mode of calls to zmq_send() plus handling the exceptions based on zmq_error() and zmq_strerror() details will let you solve the case-specific handling, as it is in details documented in the ZeroMQ API specifications.

When a ZMQ_PUSH socket enters the mute state due to having reached the high water mark for all downstream nodes, or if there are no downstream nodes at all, then any zmq_send(3) operations on the socket shall block until the mute state ends or at least one downstream node becomes available for sending; messages are not discarded.

Action in mute state: Block

user3666197
  • 1
  • 6
  • 50
  • 92