예제 #1
0
        public static void SendMessage(this IOutgoingSocket socket, KernelContext context, Message message)
        {
            // FIXME: need to handle parents for messages which are handled
            //        sequentially.

            // Conceptually, sending a message consists of three steps:
            //     • Convert the message to four frames.
            //     • Digest the four frames.
            //     • Send the identities, the delimeter, the digest, and the
            //       message frames.

            var zmqMessage = new NetMQMessage();
            var frames     = new[]
            {
                message.Header,
                message.ParentHeader,
                message.Metadata,
                message.Content
            }
            .Select(frame => JsonConvert.SerializeObject(frame))
            .Select(str => Encoding.UTF8.GetBytes(str))
            .ToList();
            var digest = context.NewHmac().ComputeHash(frames.ToArray());

            message.ZmqIdentities?.ForEach(ident => zmqMessage.Append(ident));
            zmqMessage.Append("<IDS|MSG>");
            zmqMessage.Append(BitConverter.ToString(digest).Replace("-", "").ToLowerInvariant());
            frames.ForEach(ident => zmqMessage.Append(ident));

            socket.SendMultipartMessage(zmqMessage);
        }
        public static void Send(this IOutgoingSocket socket, RawMessage message)
        {
            NetMQMessage mqMessage = new NetMQMessage();

            mqMessage.Append(message.Topic);
            mqMessage.Append(message.Header);
            mqMessage.Append(message.Body, Encoding.UTF8);
            socket.SendMultipartMessage(mqMessage);
        }
예제 #3
0
        public void Send(NodeReply msg, IOutgoingSocket outgoingSocket)
        {
            var mqMsg = Marshall(msg);

            outgoingSocket.SendMultipartMessage(mqMsg);
        }
예제 #4
0
        public void Send(RoutableMessage msg, IOutgoingSocket outgoingSocket)
        {
            var mqMsg = Marshall(msg);

            outgoingSocket.SendMultipartMessage(mqMsg);
        }
예제 #5
0
        public void Send(PointToPointMessage msg, IOutgoingSocket forwardingSocket)
        {
            var mqMsg = Marshall(msg);

            forwardingSocket.SendMultipartMessage(mqMsg);
        }
예제 #6
0
        public void Send(Message msg, IOutgoingSocket actorSocket)
        {
            var mqMsg = Marshall(msg);

            actorSocket.SendMultipartMessage(mqMsg);
        }
예제 #7
0
        /// <summary>
        /// Send the ZreMsg to the socket.
        /// </summary>
        public void Send(IOutgoingSocket output)
        {
            if (output is RouterSocket)
            {
                output.SendMoreFrame(RoutingId);
            }

            int frameSize = 2 + 1;                      //  Signature and message ID

            switch (Id)
            {
            case MessageId.Hello:
                frameSize += Hello.GetFrameSize();
                break;

            case MessageId.Whisper:
                frameSize += Whisper.GetFrameSize();
                break;

            case MessageId.Shout:
                frameSize += Shout.GetFrameSize();
                break;

            case MessageId.Join:
                frameSize += Join.GetFrameSize();
                break;

            case MessageId.Leave:
                frameSize += Leave.GetFrameSize();
                break;

            case MessageId.Ping:
                frameSize += Ping.GetFrameSize();
                break;

            case MessageId.PingOk:
                frameSize += PingOk.GetFrameSize();
                break;
            }

            //  Now serialize message into the buffer
            Msg msg = new Msg();

            msg.InitPool(frameSize);

            try
            {
                m_offset = 0;
                m_buffer = msg.Data;

                // put signature
                PutNumber2(0xAAA0 | 1);

                // put message id
                PutNumber1((byte)Id);

                switch (Id)
                {
                case MessageId.Hello:
                    Hello.Write(this);
                    break;

                case MessageId.Whisper:
                    Whisper.Write(this);
                    break;

                case MessageId.Shout:
                    Shout.Write(this);
                    break;

                case MessageId.Join:
                    Join.Write(this);
                    break;

                case MessageId.Leave:
                    Leave.Write(this);
                    break;

                case MessageId.Ping:
                    Ping.Write(this);
                    break;

                case MessageId.PingOk:
                    PingOk.Write(this);
                    break;
                }

                //  Send the data frame
                var more = Id == MessageId.Whisper || Id == MessageId.Shout;
                output.Send(ref msg, more);

                // Send message content for types with content
                switch (Id)
                {
                case MessageId.Whisper:
                    if (Whisper.Content == null)
                    {
                        Whisper.Content = new NetMQMessage();
                        Whisper.Content.PushEmptyFrame();
                    }
                    output.SendMultipartMessage(Whisper.Content);
                    break;

                case MessageId.Shout:
                    if (Shout.Content == null)
                    {
                        Shout.Content = new NetMQMessage();
                        Shout.Content.PushEmptyFrame();
                    }
                    output.SendMultipartMessage(Shout.Content);
                    break;
                }
            }
            finally
            {
                m_buffer = null;
                msg.Close();
            }
        }