/// <summary> /// Create reliable client /// </summary> /// <param name="context"></param> /// <param name="addresses">addresses of the reliable servers</param> public ReliableClient(NetMQContext context, params string[] addresses) { m_context = context; m_addresses = addresses; m_actor = NetMQActor.Create(context, Run); }
public void Simple() { using (var context = NetMQContext.Create()) { using (NetMQActor actor = NetMQActor.Create(context, shim => { shim.SignalOK(); while (true) { NetMQMessage msg = shim.ReceiveMessage(); string command = msg[0].ConvertToString(); if (command == NetMQActor.EndShimMessage) { break; } else if (command == "Hello") { shim.Send("World"); } } })) { actor.SendMore("Hello"); actor.Send("Hello"); var result = actor.ReceiveString(); Assert.AreEqual("World", result); } } }
public ReliableServer(string address) { m_address = address; // actor is like thread with builtin pair sockets connect the user thread with the actor thread m_actor = NetMQActor.Create(Run); }
public void Simple() { void ShimAction(PairSocket shim) { shim.SignalOK(); while (true) { var msg = shim.ReceiveMultipartMessage(); var command = msg[0].ConvertToString(); if (command == NetMQActor.EndShimMessage) { break; } if (command == "Hello") { Assert.AreEqual(2, msg.FrameCount); Assert.AreEqual("Hello", msg[1].ConvertToString()); shim.SendFrame("World"); } } } using (var actor = NetMQActor.Create(ShimAction)) { actor.SendMoreFrame("Hello").SendFrame("Hello"); Assert.AreEqual("World", actor.ReceiveFrameString()); } }
/// <summary> /// /// </summary> private void ServerLoop() { if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = "Nyx Hub Server Loop"; } _disposables.Add(NyxMessageStream.Subscribe(RepSocketOnReceiveReady, x => _logger.Error("Error processing stream.", x))); _hubActor?.Dispose(); _hubActor = NetMQActor.Create(new HubShimHandler(_inMessage, Port)); _logger.Debug("Starting hub server loop..."); _isStarted = true; _plugman.StartAllPlugins(); _nodeStatusSubject.OnNext(NyxNodeStatus.Started); // Endless loop until request to stop, then shutdowns while (!_serverCancelToken.IsCancellationRequested) { _serverEvent.WaitOne(TimeSpan.FromSeconds(60)); } _plugman.StopAllPlugins(); Status = NyxNodeStatus.Stopped; _nodeStatusSubject.OnNext(Status); try { _hubActor?.SendFrame(NetMQActor.EndShimMessage); _hubActor?.Dispose(); } catch (TerminatingException) { // Ignore and go } _isStarted = false; }
public void Simple() { using (var context = NetMQContext.Create()) { ShimAction shimAction = shim => { shim.SignalOK(); while (true) { NetMQMessage msg = shim.ReceiveMultipartMessage(); string command = msg[0].ConvertToString(); if (command == NetMQActor.EndShimMessage) { break; } if (command == "Hello") { shim.SendFrame("World"); } } }; using (var actor = NetMQActor.Create(context, shimAction)) { actor.SendMoreFrame("Hello").SendFrame("Hello"); Assert.AreEqual("World", actor.ReceiveFrameString()); } } }
public void Start() { if (_actor != null) { return; } _actor = NetMQActor.Create(new ShimHandler()); }
public ReliableServer(TimeSpan heartbeatInterval, string address) { _address = address; _heartbeatInterval = heartbeatInterval; // actor is like thread with builtin pair sockets connect the user thread with the actor thread _actor = NetMQActor.Create(Run); }
public void Start() { if (actor != null) { return; } actor = NetMQActor.Create(new ShimHandler(Address, (topic, value) => RaiseSubscriberMessageReceived(topic, value))); }
public PeerBus(IHubContext <NotificationHub> hub, IOptions <WebServerOptions> options, ILogger <PeerBus> logger) { _id = $"[{options.Value.ServerId}]"; _info = new Dictionary <PeerInfo, DateTimeOffset>(); _beaconPort = options.Value.BeaconPort; _hub = hub; _logger = logger; _actor = NetMQActor.Create(RunActor); }
public ReliableServer(TimeSpan heartbeatInterval, string address, int receiveTimeout = 0, Action onReceiveTimeout = null) { _address = address; _receiveTimeout = receiveTimeout; _onReceiveTimeout = onReceiveTimeout; _heartbeatInterval = heartbeatInterval; // actor is like thread with builtin pair sockets connect the user thread with the actor thread _actor = NetMQActor.Create(Run); }
/// <summary> /// Init or reinit all communications. /// </summary> public void Init() { if (Interlocked.CompareExchange(ref _requiresInitialisation, 0, 1) == 0) { return; } _actor?.SendFrame(NetMQActor.EndShimMessage); _actor?.Dispose(); _actor = NetMQActor.Create(new ShimHandler(this, _connectionSubject, _address, _port)); }
/// <summary> /// Create reliable client /// </summary> /// <param name="reconnectInterval"></param> /// <param name="subscriberMessageHandler"></param> /// <param name="subscriberErrorHandler"></param> /// <param name="addresses">addresses of the reliable servers</param> /// <param name="heartbeatTimeOut"></param> public ReliableClient(IEnumerable <string> addresses, TimeSpan heartbeatTimeOut, TimeSpan reconnectInterval, Action <NetMQMessage> subscriberMessageHandler = null, Action <Exception, NetMQMessage> subscriberErrorHandler = null, Action welcomeMessageHandler = null) { _heartbeatTimeOut = heartbeatTimeOut; _reconnectInterval = reconnectInterval; _addresses = addresses; _subscriberMessageHandler = subscriberMessageHandler; _subscriberErrorHandler = subscriberErrorHandler; _welcomeMessageHandler = welcomeMessageHandler; _actor = NetMQActor.Create(Run); }
/// <summary> /// 构造 /// </summary> /// <param name="address"></param> /// <param name="shimCreator"></param> protected WsSocket(string address, Func <int, string, BaseShimHandler> shimCreator) { Id = Interlocked.Increment(ref _id); _messagesPipe = new PairSocket(); _messagesPipe.Bind($"inproc://wsrouter-{Id}"); _messagesPipe.ReceiveReady += OnMessagePipeReceiveReady; _actor = NetMQActor.Create(ShimHandler = shimCreator(Id, address)); _messagesPipe.ReceiveSignal(); }
public SnapshotServer(string address, ISnapshotGenerator snapshotGenerator) { if (snapshotGenerator == null) { throw new ArgumentNullException(nameof(snapshotGenerator)); } _address = address; _snapshotGenerator = snapshotGenerator; _actor = NetMQActor.Create(Run); }
public void BadCommandTests(string command) { const string actorMessage = "whatever"; using (var actor = NetMQActor.Create(new EchoShimHandler())) { actor.SendMoreFrame(command); actor.SendFrame(actorMessage); Assert.AreEqual("Error: invalid message to actor", actor.ReceiveFrameString()); } }
public void ShimExceptionTest() { using (var actor = NetMQActor.Create(new ExceptionShimHandler())) { actor.SendMoreFrame("SOME_COMMAND"); actor.SendFrame("Whatever"); Assert.AreEqual( "Error: Exception occurred Actors Shim threw an Exception", actor.ReceiveFrameString()); } }
public void EchoActorSendReceiveTests(string actorMessage) { using (var actor = NetMQActor.Create(new EchoShimHandler())) { actor.SendMoreFrame("ECHO"); actor.SendFrame(actorMessage); Assert.AreEqual( $"ECHO BACK : {actorMessage}", actor.ReceiveFrameString()); } }
protected WSSocket(Func <int, IShimHandler> shimCreator) { int id = Interlocked.Increment(ref s_id); m_messagesPipe = new PairSocket(); m_messagesPipe.Bind(string.Format("inproc://wsrouter-{0}", id)); m_messagesPipe.ReceiveReady += OnMessagePipeReceiveReady; m_actor = NetMQActor.Create(shimCreator(id)); m_messagesPipe.ReceiveSignal(); }
public void EchoActorSendReceiveTests(string actorMessage) { using (var context = NetMQContext.Create()) using (var actor = NetMQActor.Create(context, new EchoShimHandler())) { actor.SendMore("ECHO"); actor.Send(actorMessage); Assert.AreEqual( string.Format("ECHO BACK : {0}", actorMessage), actor.ReceiveFrameString()); } }
private NetMQActor CreateActor() { return(NetMQActor.Create(shim => { Shim = shim; Shim.ReceiveReady += ShimOnReceiveReady; Shim.SignalOK(); Poller.Add(Shim); Poller.Add(ListeningSocket); Poller.Run(); Log("Node closed"); })); }
private NetMQActor CreateActor() { return(NetMQActor.Create(shim => { Shim = shim; Shim.ReceiveReady += ShimOnReceiveReady; Poller.Add(ListeningSocket); Poller.Add(InitTimer); Poller.Add(Shim); Shim.SignalOK(); Poller.Run(); })); }
public void AccountActorJsonSendReceiveTests() { var account = new Account(1, "Test Account", "11223", 0); var accountAction = new AccountAction(TransactionType.Credit, 10); using (var actor = NetMQActor.Create(new AccountShimHandler())) { actor.SendMoreFrame("AMEND ACCOUNT"); actor.SendMoreFrame(JsonConvert.SerializeObject(accountAction)); actor.SendFrame(JsonConvert.SerializeObject(account)); var updatedAccount = JsonConvert.DeserializeObject <Account>(actor.ReceiveFrameString()); Assert.Equal(10.0m, updatedAccount?.Balance ?? 0); } }
private ZyreNode(PairSocket outbox, Action <string> loggerDelegate = null) { _outbox = outbox; _loggerDelegate = loggerDelegate; _beaconPort = ZreDiscoveryPort; _interval = TimeSpan.Zero; // Use default _uuid = Guid.NewGuid(); _peers = new Dictionary <Guid, ZyrePeer>(); _peerGroups = new Dictionary <string, ZyreGroup>(); _ownGroups = new Dictionary <string, ZyreGroup>(); _headers = new Dictionary <string, string>(); // Default name for node is first 6 characters of UUID: // the shorter string is more readable in logs _name = _uuid.ToShortString6(); // Use ZMQ_ROUTER_HANDOVER so that when a peer disconnects and // then reconnects, the new client connection is treated as the // canonical one, and any old trailing commands are discarded. // This RouterHandover option is currently not supported in NetMQ Feb 16 2016 _actor = NetMQActor.Create(RunActor); }
/// <summary> /// Create new server /// </summary> /// <param name="serializer">Serializer to use to serialize messages</param> /// <param name="asyncHandler">Handler to handle messages from client</param> public AsyncServer(ISerializer serializer, IAsyncHandler asyncHandler) { m_actor = NetMQActor.Create(new AsyncServerEngine(serializer, asyncHandler)); }
private Bus(int broadcastPort) { m_nodes = new Dictionary <NodeKey, DateTime>(); m_broadcastPort = broadcastPort; m_actor = NetMQActor.Create(RunActor); }
public ReliableServer(string endpoint) { _address = endpoint; _actor = NetMQActor.Create(Run); }
public void Init() => m_actor = NetMQActor.Create(Engine);
/// <summary> /// Create new client /// </summary> /// <param name="serializer">Serialize to to use to serialize the message to byte array</param> /// <param name="address">Address of the server</param> public Client(ISerializer serializer, string address) { m_outgoingQueue = new NetMQQueue <ClientEngine.OutgoingMessage>(); m_actor = NetMQActor.Create(new ClientEngine(serializer, m_outgoingQueue, address)); }
/// <summary> /// Create reliable client /// </summary> /// <param name="context"></param> /// <param name="addresses">addresses of the reliable servers</param> public ReliableClient(params string[] addresses) { m_addresses = addresses; m_actor = NetMQActor.Create(Run); }