0

在初始化我的路由器应用程序时,我调用以下代码。它绑定得很好,接收消息很好,但拒绝为 On_ReceiveXXX 方法工作,除非它是直接响应。我想知道为什么

    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 事件:

私人无效 On_ReceiveFrontEnd(对象发送者,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));

        _backEnd.SendMultipartBytes(frontEndMsg);
    }

但是如果我换行

 _backEnd.SendMultipartBytes(frontEndMsg);

_frontEnd.SendMultipartBytes(frontEndMsg);

它突然起作用了......所以来自我的前端应用程序的消息只能被响应,而不是传递给后端应用程序。反过来,对于后端消息也是如此。

4

1 回答 1

0

使用路由器时,第一帧是路由 ID,它特定于套接字。因此,您无法将整个消息从路由器传递到路由器。将后端更改为经销商,它将起作用,或者在消息前面加上后端套接字的路由 id。

于 2015-10-27T20:45:59.403 回答