Ejemplo n.º 1
0
        public void MessageBinarySerialization()
        {
            var messageBody = "Test message";
            var msg = new Message() {
                Body = Encoding.Unicode.GetBytes(messageBody),
            };
            msg.Headers.Add("Token1", "3000");
            msg.Headers.Add("Token2", "2000");
            msg.Headers.Add("Token3", "1000");

            var serialized = msg.ToByteArray();

            var msg2 = serialized.FromByteArray();
            var b1 = Encoding.Unicode.GetString(msg.Body);
            var b2 = Encoding.Unicode.GetString(msg2.Body);

            Assert.AreEqual(msg.MessageId, msg2.MessageId);
            Assert.AreEqual(msg.CorrelationId, msg2.CorrelationId);
            Assert.AreEqual(msg.CorrelationId, msg2.CorrelationId);
            Assert.AreEqual(b1, b2);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="msg"></param>
        /// <param name="onMessageSent"></param>
        public void SendAsync(IConnection connection, Message msg, Action<IConnection,Message> onMessageSent)
        {
            var conn = connection as TcpConnection<MessageBuilder>;
            
            conn.State.OnMessageSent = onMessageSent;

            var data = msg.ToByteArray();

            conn.Handler.BeginSend(data, 0
                , data.Length
                , SocketFlags.None
                , new AsyncCallback(SendCallback), Tuple.Create(conn, msg) );
        }