internal void OnRecvMsg(BaseZmqWorker worker, ZMessage recvMsg)
        {
            using (recvMsg)
            {
                var startTime = DateTime.UtcNow;
                using (recvMsg)
                {
                    var clientAddr     = recvMsg[0];
                    var clientData     = recvMsg[2].Read();
                    var baseRequestMsg = MsgPackTool.GetMsg <BaseRequestMsg>(clientData);
                    var requestDataMsg = baseRequestMsg.Data;

                    var responseTask = ProcessRequest(requestDataMsg);
                    responseTask.Wait();
                    var responseMsg = responseTask.Result;

                    // if no session key, generate new
                    var sessionToken = baseRequestMsg.SessionToken;
                    if (string.IsNullOrEmpty(sessionToken))
                    {
                        sessionToken = GenerateSessionKey();
                    }
                    var baseResponseMsg = new BaseResponseMsg()
                    {
                        SessionToken = sessionToken,
                        RequestToken = baseRequestMsg.RequestToken,
                        Data         = responseMsg,
                    };

                    var sendData = MsgPackTool.GetBytes(baseResponseMsg);

                    var messageToServer = new ZMessage();
                    messageToServer.Append(clientAddr);
                    messageToServer.Append(ZFrame.CreateEmpty());
                    messageToServer.Append(new ZFrame(sendData));
                    worker.workerSocket.SendMessage(messageToServer);
                }

                Logger.Trace("Receive Msg and Send used Time: {0:F5}s", (DateTime.UtcNow - startTime).TotalSeconds);
            }
        }
Exemple #2
0
 void AddWorker()
 {
     var worker = new BaseZmqWorker(this, ServerBackendAddr, CurWorkerIndex++);
     _workers.Add(worker);
 }
        void AddWorker()
        {
            var worker = new BaseZmqWorker(this, ServerBackendAddr, CurWorkerIndex++);

            _workers.Add(worker);
        }
Exemple #4
0
        internal void OnRecvMsg(BaseZmqWorker worker, ZMessage recvMsg)
        {
            using (recvMsg)
            {
                var startTime = DateTime.UtcNow;
                using (recvMsg)
                {
                    var clientAddr = recvMsg[0];
                    var clientData = recvMsg[2].Read();
                    var baseRequestMsg = MsgPackTool.GetMsg<BaseRequestMsg>(clientData);
                    var requestDataMsg = baseRequestMsg.Data;

                    var responseTask = ProcessRequest(requestDataMsg);
                    responseTask.Wait();
                    var responseMsg = responseTask.Result;

                    // if no session key, generate new
                    var sessionToken = baseRequestMsg.SessionToken;
                    if (string.IsNullOrEmpty(sessionToken))
                    {
                        sessionToken = GenerateSessionKey();
                    }
                    var baseResponseMsg = new BaseResponseMsg()
                    {
                        SessionToken = sessionToken,
                        RequestToken = baseRequestMsg.RequestToken,
                        Data = responseMsg,
                    };

                    var sendData = MsgPackTool.GetBytes(baseResponseMsg);

                    var messageToServer = new ZMessage();
                    messageToServer.Append(clientAddr);
                    messageToServer.Append(ZFrame.CreateEmpty());
                    messageToServer.Append(new ZFrame(sendData));
                    worker.workerSocket.SendMessage(messageToServer);
                }

                Logger.Trace("Receive Msg and Send used Time: {0:F5}s", (DateTime.UtcNow - startTime).TotalSeconds);
            }
        }