/// <summary> /// Connect or re-connect to the broker. /// </summary> private void Connect() { // if the socket exists dispose it and re-create one if (!ReferenceEquals(m_worker, null)) { m_worker.Unbind(m_brokerAddress); m_worker.Dispose(); } m_worker = new DealerSocket(); // set identity if provided if (m_identity != null && m_identity.Length > 0) { m_worker.Options.Identity = m_identity; } // hook up the received message processing method before the socket is connected m_worker.ReceiveReady += ProcessReceiveReady; m_worker.Connect(m_brokerAddress); Log($"[WORKER] connected to broker at {m_brokerAddress}"); // signal that worker is connected m_connected = true; // send READY to broker since worker is connected Send(MDPCommand.Ready, m_serviceName, null); // reset liveliness to active broker m_liveliness = _heartbeat_liveliness; }
/// <summary> /// connect or re-connect to the broker /// </summary> private void Connect() { // if the socket exists dispose it and re-create one if (!ReferenceEquals(m_worker, null)) { m_worker.Unbind(m_brokerAddress); m_worker.Dispose(); } m_worker = m_ctx.CreateDealerSocket(); // set identity if provided if (m_identity != null && m_identity.Length > 0) { m_worker.Options.Identity = m_identity; } // hook up the received message processing method before the socket is connected m_worker.ReceiveReady += ProcessReceiveReady; m_worker.Connect(m_brokerAddress); Log(string.Format("[WORKER] connected to broker at {0}", m_brokerAddress)); // signal that worker is connected m_connected = true; // send READY to broker since worker is connected Send(MDPCommand.Ready, m_serviceName, null); // reset liveliness to active broker m_liveliness = _HEARTBEAT_LIVELINESS; // set point in time for next heatbeat m_heartbeatAt = DateTime.UtcNow + HeartbeatDelay; }
/// <summary> /// Stops the server /// </summary> public void Stop() { isDone = true; listenerThread.Join(); netMqSocket.Unbind(serverConnectionString); netMqSocket.Close(); }
internal static void Stop(this NetMQSocket socket, string address, SocketType socketType) { switch (socketType) { case SocketType.Client: socket.Disconnect(address); break; case SocketType.Server: socket.Unbind(address); break; default: throw new ArgumentException(string.Format("Unknown SocketType {0}", socketType), "socketType"); } socket.Close(); }
/// <summary> /// Unbind the socket from last endpoint and wait until the underlaying socket was unbound and disposed. /// It will also dispose the NetMQSocket /// </summary> /// <param name="sub"></param> public static void Unbind(this NetMQSocket sub) { using (var monitor = new NetMQMonitor(sub, $"inproc://unbind.wait.{Counter++}", SocketEvents.Closed)) { var monitorTask = Task.Factory.StartNew(monitor.Start); var closed = new ManualResetEventSlim(); monitor.Closed += (sender, args) => closed.Set(); Assert.IsNotNull(sub.Options.LastEndpoint); sub.Unbind(sub.Options.LastEndpoint); closed.Wait(1000); monitor.Stop(); monitorTask.Wait(); } }
public void Unbind(string address) { Socket.Unbind(address); EndPoints.Remove(address); }
public void Unbind(Uri address) => socket.Unbind(address.ToSocketAddress());