本文整理汇总了C#中ZeroMQ.ZContext.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ZContext.Dispose方法的具体用法?C# ZContext.Dispose怎么用?C# ZContext.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZeroMQ.ZContext
的用法示例。
在下文中一共展示了ZContext.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
public void Send(string endPoint, Type type, byte[] message, Dictionary<string, string> headers = null)
{
lock (_lock)
{
Dictionary<string, object> messageHeaders = GetHeaders(type, headers, endPoint, "Send");
var serializedHeaders = JsonConvert.SerializeObject(messageHeaders);
var msg = new ZMessage();
msg.Append(new ZFrame(serializedHeaders));
msg.Append(new ZFrame(message));
// Reconnect if enpoint changed since the last message was sent.
//if (_senderEndpoint != endPoint)
//{
_senderEndpoint = endPoint;
_senderContext = new ZContext();
_sender = new ZSocket(_senderContext, ZSocketType.REQ);
_sender.Connect(endPoint);
//}
// Send
var poll = ZPollItem.CreateReceiver();
var timeout = TimeSpan.FromMilliseconds(1);
ZError error;
int retriesLeft = 3;
while (retriesLeft > 0)
{
// Outgoing
if (!_sender.SendMessage(msg, out error))
{
if (error == ZError.ETERM)
return; // Interrupted
throw new ZException(error);
}
// Incoming
ZMessage incoming;
while (true)
{
if (_sender.PollIn(poll, out incoming, out error, timeout))
{
using (incoming)
{
retriesLeft = 0;
break;
}
}
else
{
if (error == ZError.EAGAIN)
{
if (--retriesLeft == 0)
{
Logger.Error("Server seems to be offline, abandoning");
break;
}
Logger.Warn("No response from server, retrying…");
// Old socket is confused; close it and open a new one
_sender.Dispose();
_sender = new ZSocket(_senderContext, ZSocketType.REQ);
_sender.Connect(endPoint);
Logger.Info("I: reconnected");
// Send request again, on new socket
if (!_sender.SendMessage(msg, out error))
{
if (error == ZError.ETERM)
return; // Interrupted
throw new ZException(error);
}
continue;
}
if (error == ZError.ETERM)
return; // Interrupted
throw new ZException(error);
}
}
}
_sender.Dispose();
_senderContext.Dispose();
}
}