Пример #1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="producer">消息生产者</param>
        /// <param name="object">消息对象</param>
        /// <param name="route">消息路由</param>
        /// <param name="jsonSerilizer">json序列化对象,可以使用 Never.JsonNet.JsonNetSerializer对象 </param>
        public static void SendMessage <T>(this IMessageProducer producer, T @object, IJsonSerializer jsonSerilizer, IMessageRoute route = null)
        {
            if (@object == null)
            {
                return;
            }

            producer.Send(MessagePacket.UseJson(@object, jsonSerilizer), route);
        }
Пример #2
0
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="producer">消息生产者</param>
 /// <param name="object">消息对象</param>
 /// <param name="route">消息路由</param>
 /// <param name="jsonSerilizer">json序列化对象,可以使用 Never.JsonNet.JsonNetSerializer对象 </param>
 public static Task SendMessageAsync <T>(this IMessageProducer producer, T @object, IJsonSerializer jsonSerilizer, IMessageRoute route = null)
 {
     return(Task.Factory.StartNew(() =>
     {
         if (@object != null)
         {
             producer.Send(MessagePacket.UseJson <T>(@object, jsonSerilizer), route);
         }
     }));
 }
Пример #3
0
        public void Publish <TEvent>(ICommandContext commandContext, TEvent e) where TEvent : IEvent
        {
            if (e == null)
            {
                return;
            }

            this.Startup();

            var producer = this.messageProducerProvider.MessageProducer;

            producer.Send(MessagePacket.UseJson(e, this.messageProducerProvider.JsonSerilizer));
        }
Пример #4
0
        public void TestSerTestMessage()
        {
            var msg = new TestMessage()
            {
                Id    = 9,
                Name  = "adg",
                Other = "ete"
            };

            var packet = MessagePacket.UseJson(msg);

            var b = new Never.Serialization.BinarySerializer().Serialize(packet);

            var b2 = new Never.ProtoBuf.MessageSerializer().Serialize(packet);

            var tt = new Never.ProtoBuf.MessageSerializer().Deserialize <MessagePacket>(b2);
        }
Пример #5
0
        public void Push(ICommandContext context, IEnumerable <IEvent[]> events)
        {
            if (events == null)
            {
                return;
            }

            this.Startup();

            var producer = this.messageProducerProvider.MessageProducer;

            foreach (var splits in events)
            {
                if (splits.IsNullOrEmpty())
                {
                    continue;
                }

                foreach (var split in splits)
                {
                    producer.Send(MessagePacket.UseJson(split, this.messageProducerProvider.JsonSerilizer));
                }
            }
        }