NetMQ - messages only work on reply to incoming message, not to other port
初始化路由器应用程序时,我调用以下代码。它绑定罚款,接收消息罚款,但拒绝为on-receivexxx方法工作,除非它是直接响应。我想知道为什么
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | public void Initialize(string frontEndAddress, string backEndAddress) { _poller = new Poller(); _timeAllowedBetweenPings = TimeSpan.FromMinutes(1); _lastPingResponse = DateTime.Now; using (var ctx = NetMQContext.Create()) { _frontEnd = ctx.CreateRouterSocket(); _backEnd = ctx.CreateRouterSocket(); _frontEnd.Bind(frontEndAddress); Console.WriteLine(string.Format("[Router]: Connected to {0}", frontEndAddress)); _backEnd.Bind(backEndAddress); Console.WriteLine(string.Format("[Router]: Connected to {0}", backEndAddress)); _frontEnd.ReceiveReady += On_ReceiveFrontEnd; _backEnd.ReceiveReady += On_ReceiveBackEnd; _poller.AddSocket(_frontEnd); _poller.AddSocket(_backEnd); var timer = new NetMQTimer(TimeSpan.FromSeconds(1)); timer.Elapsed += On_Ping; _poller.AddTimer(timer); _poller.PollTillCancelled(); } } |
这无法调用经销商Receiveready事件:
_receivefrontend上的私有void(对象发送方,netmqsocketEventargs e){_ lastPingResponse=datetime.now;var frontendmsg=e.socket.receivemultipartbytes();var streamdata=frontendmsg.last();applicationmessage msg=packagehelper.deserializeoutgoing(streamdata);console.writeline(string.format("收到的命令:0",msg.co));
1 2 | _backEnd.SendMultipartBytes(frontEndMsg); } |
但是如果我改变路线
1 | _backEnd.SendMultipartBytes(frontEndMsg); |
到
1 | _frontEnd.SendMultipartBytes(frontEndMsg); |
它突然生效了…所以来自前端应用程序的消息只能响应,而不能传递给后端应用程序。另一方面,后端消息也是如此。
使用路由器时,第一个帧是路由ID,它特定于套接字。所以不能将整个消息从路由器传递到路由器。将后端更改为"经销商",它将工作,或者在消息前面加上后端套接字的路由ID。