public void TestRoundTrip()
        {
            NetworkBinaryWriter w = Writer();

            StreamWireFormatting.WriteBool(w, true);
            StreamWireFormatting.WriteInt32(w, 1234);
            StreamWireFormatting.WriteInt16(w, 1234);
            StreamWireFormatting.WriteByte(w, 123);
            StreamWireFormatting.WriteChar(w, 'x');
            StreamWireFormatting.WriteInt64(w, 1234);
            StreamWireFormatting.WriteSingle(w, 1.234f);
            StreamWireFormatting.WriteDouble(w, 1.234);
            StreamWireFormatting.WriteBytes(w, new byte[] { 1, 2, 3, 4 });
            StreamWireFormatting.WriteString(w, "hello");
            StreamWireFormatting.WriteObject(w, "world");
            NetworkBinaryReader r = Reader(Contents(w));

            Assert.AreEqual(true, StreamWireFormatting.ReadBool(r));
            Assert.AreEqual(1234, StreamWireFormatting.ReadInt32(r));
            Assert.AreEqual(1234, StreamWireFormatting.ReadInt16(r));
            Assert.AreEqual(123, StreamWireFormatting.ReadByte(r));
            Assert.AreEqual('x', StreamWireFormatting.ReadChar(r));
            Assert.AreEqual(1234, StreamWireFormatting.ReadInt64(r));
            Assert.AreEqual(1.234f, StreamWireFormatting.ReadSingle(r));
            Assert.AreEqual(1.234, StreamWireFormatting.ReadDouble(r));
            Assert.AreEqual(new byte[] { 1, 2, 3, 4 }, StreamWireFormatting.ReadBytes(r));
            Assert.AreEqual("hello", StreamWireFormatting.ReadString(r));
            Assert.AreEqual("world", StreamWireFormatting.ReadObject(r));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 推送消息
        /// </summary>
        /// <param name="exchange"></param>
        /// <param name="routingKey"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public bool BasicPublish(string exchange, string routingKey, string context)
        {
            try
            {
                NetworkBinaryWriter networkBinaryReader = new NetworkBinaryWriter(new MemoryStream());
                StreamWireFormatting.WriteString(networkBinaryReader, "nihao");

                //消息属性
                //  var propertity=  channel.CreateBasicProperties();
                //消息推送
                channel.BasicPublish(exchange, routingKey, null, Encoding.UTF8.GetBytes(context));
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Writes a <see cref="float"/>string value into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteString(string value)
 {
     StreamWireFormatting.WriteString(Writer, value);
     return(this);
 }