Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
0
        /// <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(queue); //获取连接
            //EventLog.Log(exChange, "mq");
            using (Context.SendConnection)
            {
                Context.SendChannel = RabbitMqClientFactory.CreateModel(Context.SendConnection); //获取通道
                Context.SendChannel.QueueDeclare(queue: queue, durable: true, exclusive: false, autoDelete: false, arguments: null);
                const byte deliveryMode = 2;
                using (Context.SendChannel)
                {
                    var messageSerializer = MessageSerializerFactory.CreateMessageSerializerInstance(); //反序列化消息

                    var properties = Context.SendChannel.CreateBasicProperties();
                    properties.DeliveryMode = deliveryMode; //表示持久化消息
                    //EventLog.Log("que:" + queue, "mq");
                    //推送消息
                    Context.SendChannel.BasicPublish(
                        exChange, queue, properties, messageSerializer.SerializerBytes(eventMessage));
                    //EventLog.Log("exchange:" + exChange, "mq");
                    //EventLog.Log("exchange:" + queue, "mq");
                }
            }
        }