コード例 #1
0
        public void Execute(IJobExecutionContext context)
        {
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    var js = JsonConvert.SerializeObject(_msg);
                    //正文填充
                    var s = System.Text.Encoding.UTF8.GetBytes(js, 0, js.Length, minute_buf, 32);

                    if (s > (2 * 1024 - 32))
                    {
                        throw new ArgumentOutOfRangeException("正文数据超出范围");
                    }

                    //头部填充
                    minute_buf[0x00] = 0x01;
                    Program.AppSourceID.ToBytesWithEndianBit(minute_buf, 0x01, BitConvertEx.BitConverterEx.EndianBitType.BigEndian);
                    UInt64 utc_now = (UInt64)DateTimeTool.GetTimeUtcstamp(DateTime.Now);
                    utc_now.ToBytesWithEndianBit(minute_buf, 0x05, BitConvertEx.BitConverterEx.EndianBitType.BigEndian);
                    MessageTypeID.ToBytesWithEndianBit(minute_buf, 0x0D, BitConvertEx.BitConverterEx.EndianBitType.BigEndian);
                    UInt64 expired_time = 0U;
                    expired_time.ToBytesWithEndianBit(minute_buf, 0x11, BitConvertEx.BitConverterEx.EndianBitType.BigEndian);
                    UInt16 context_len = (UInt16)s;
                    context_len.ToBytesWithEndianBit(minute_buf, 0x19, BitConvertEx.BitConverterEx.EndianBitType.BigEndian);

                    channel.ExchangeDeclare(exchange: Program.exchange_name, type: "topic");
                    channel.BasicPublish(exchange: Program.exchange_name,
                                         routingKey: "01020304.MinuteTick",
                                         basicProperties: null,
                                         body: minute_buf
                                         );
                }
            }
        }
コード例 #2
0
        public void TestUInt16ToBytesByForceBigEndianBit()
        {
            UInt16 src    = UInt16.MaxValue;
            var    buffer = new byte[2];

            src.ToBytesWithEndianBit(buffer, 0, BitConverterEx.EndianBitType.BigEndian);
            UInt16 res = buffer.GetUInt16WithEndianBit(0, BitConverterEx.EndianBitType.BigEndian);

            Assert.AreEqual(res, src);
        }
コード例 #3
0
        public void TestUInt16ToBytesByDefault()
        {
            UInt16 src    = UInt16.MaxValue;
            var    buffer = new byte[2];

            src.ToBytesWithEndianBit(buffer);
            UInt16 res = buffer.GetUInt16WithEndianBit();

            Assert.AreEqual(res, src);
        }