コード例 #1
0
        /// <summary>
        /// 生成EventMessageResult对象。
        /// </summary>
        /// <param name="bytes">流</param>
        /// <returns>EventMessageResult instance.</returns>
        internal static EventMessageResult BuildEventMessageResult(byte[] bytes)
        {
            var eventMessage =
                MessageSerializerFactory.CreateMessageSerializerInstance().Deserialize <EventMessage>(bytes);

            var result = new EventMessageResult
            {
                MessageBytes      = eventMessage.EventMessageBytes,
                EventMessageBytes = eventMessage
            };

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 创建EventMessage传输对象。
        /// </summary>
        /// <param name="originObject">原始强类型对象实例。</param>
        /// <param name="eventMessageMarkcode">消息的标记码。</param>
        /// <typeparam name="T">原始对象类型。</typeparam>
        /// <returns>EventMessage.</returns>
        public static EventMessage CreateEventMessageInstance <T>(T originObject, string eventMessageMarkcode)
            where T : class, new()
        {
            var result = new EventMessage()
            {
                CreateDateTime       = DateTime.Now,
                EventMessageMarkcode = eventMessageMarkcode
            };

            var bytes = MessageSerializerFactory.CreateMessageSerializerInstance().SerializerBytes <T>(originObject);

            result.EventMessageBytes = bytes;

            return(result);
        }
コード例 #3
0
ファイル: RabbitMqClient.cs プロジェクト: chinakarl/rabbitMQ
        /// <summary>
        /// 触发一个事件且将事件打包成消息发送到远程队列中。
        /// </summary>
        /// <param name="eventMessage">发送的消息实例。</param>
        /// <param name="exChange">RabbitMq的Exchange名称。</param>
        /// <param name="queue">队列名称。</param>
        public void TriggerEventMessage(EventMessage eventMessage, string exChange, string queue)
        {
            Context.SendConnection = RabbitMqClientFactory.CreateConnection(); //获取连接

            using (Context.SendConnection)
            {
                Context.SendChannel = RabbitMqClientFactory.CreateModel(Context.SendConnection); //获取通道

                const byte deliveryMode = 2;
                using (Context.SendChannel)
                {
                    var messageSerializer = MessageSerializerFactory.CreateMessageSerializerInstance(); //反序列化消息

                    var properties = Context.SendChannel.CreateBasicProperties();
                    properties.DeliveryMode = deliveryMode; //表示持久化消息

                    //推送消息
                    Context.SendChannel.BasicPublish(exChange, queue, true, properties, messageSerializer.SerializerBytes(eventMessage));
                }
            }
        }