Пример #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);
        }
        /// <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
 /// <summary>
 /// 触发一个事件且将事件打包成消息发送到远程队列中
 /// </summary>
 /// <param name="eventMessage">发送的消息实例</param>
 /// <param name="exchange">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, properties, messageSerializer.SerializerBytes(eventMessage));
         }
     }
 }