/// <summary> /// Create a Zyre API that communicates with a node on the ZRE bus. /// </summary> /// <param name="name">The name of the node</param> /// <param name="useEvents">Set this to true to disable Receive() and instead subscribe to events for getting messages from peers. Default is true.</param> /// <param name="loggerDelegate">An action to take for logging when _verbose is true. Default is null.</param> public Zyre(string name, bool useEvents = true, Action <string> loggerDelegate = null) { _useEvents = useEvents; // Create front-to-back pipe pair for data traffic // outbox is passed to ZyreNode for sending Zyre message traffic back to _inbox PairSocket outbox; PairSocket.CreateSocketPair(out outbox, out _inbox); // Start node engine and wait for it to be ready // All node control is done through _actor _actor = ZyreNode.Create(outbox, loggerDelegate); if (useEvents) { _inboxPoller = new NetMQPoller(); _inbox.ReceiveReady += InboxReceiveReady; _inboxPoller.RunAsync(); } // Send name, if any, to node ending if (!string.IsNullOrEmpty(name)) { _actor.SendMoreFrame("SET NAME").SendFrame(name); } }
/// <summary> /// Create a new node and return the actor that controls it. /// All node control is done through _actor. /// outbox is passed to ZyreNode for sending Zyre message traffic back to caller. /// </summary> /// <param name="outbox">the pipe for sending messages from peers back to Zyre.cs</param> /// <param name="loggerDelegate">An action to take for logging when _verbose is true. Default is null.</param> /// <returns>the _actor, or null if not successful</returns> internal static NetMQActor Create(PairSocket outbox, Action<string> loggerDelegate = null) { var node = new ZyreNode(outbox, loggerDelegate); return node._actor; }
/// <summary> /// Create a new node and return the actor that controls it. /// All node control is done through _actor. /// outbox is passed to ZyreNode for sending Zyre message traffic back to caller. /// </summary> /// <param name="outbox">the pipe for sending messages from peers back to Zyre.cs</param> /// <param name="loggerDelegate">An action to take for logging when _verbose is true. Default is null.</param> /// <returns>the _actor, or null if not successful</returns> internal static NetMQActor Create(PairSocket outbox, Action <string> loggerDelegate = null) { var node = new ZyreNode(outbox, loggerDelegate); return(node._actor); }