示例#1
0
        /// <summary>
        /// 发送一个事件,该事件会被包装为<see cref="MessagePacket"/>类型,并发送到指定队列中,其中ContentType为事件类型,Body为事件被序列化后的内容
        /// </summary>
        /// <param name="e">The e.</param>
        protected virtual void Send(IEvent e)
        {
            if (this.messageProducer == null)
            {
                return;
            }

            this.Startup();

            try
            {
                this.messageProducer.Send(new MessagePacket()
                {
                    ContentType = MessagePacket.GetContentType(e),
                    Body        = this.jsonSerializer.SerializeObject(e),
                }, null);
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }
示例#2
0
        /// <summary>
        /// 发送一个命令,该命令会被包装为<see cref="CommandStreamMessage"/> 并发送到指定队列中
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command">The command</param>
        protected virtual void Send <T>(T command) where T : ICommand
        {
            if (this.messageProducer == null)
            {
                return;
            }

            this.Startup();

            try
            {
                this.messageProducer.Send(new MessagePacket()
                {
                    ContentType = MessagePacket.GetContentType(typeof(T)),
                    Body        = this.jsonSerializer.Serialize(command),
                }, null);
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }
示例#3
0
        /// <summary>
        /// 发送一个命令,该命令会被包装为<see cref="CommandStreamMessage"/> 并发送到指定队列中
        /// </summary>
        /// <param name="e">The e.</param>
        protected virtual void Send(IOperateCommand e)
        {
            if (this.messageProducer == null)
            {
                return;
            }

            this.Startup();

            var message = e.ConvertTo(this.jsonSerializer);

            try
            {
                this.messageProducer.Send(new MessagePacket()
                {
                    ContentType = MessagePacket.GetContentType(message),
                    Body        = this.jsonSerializer.Serialize(message),
                }, null);
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }