Example #1
0
 /// <summary>
 /// Event Publish to mq
 /// </summary>
 /// <param name="event"><see cref="IEvent"/></param>
 /// <returns></returns>
 internal async Task PublishEventAsync(IEvent @event, MQPublishType publishType = MQPublishType.Asynchronous)
 {
     if (publishType == MQPublishType.NotPublish)
     {
         return;
     }
     try
     {
         if (@event == null)
         {
             throw new ArgumentNullException("PublishEventAsync event cannot be empty");
         }
         if (this.PublishOptions != null)
         {
             await _mqPublisher.PublishAsync(@event, this.PublishOptions.Topic, this.PublishOptions.MQProvider, publishType);
         }
         var opt = this._internalConfiguration.GetEventPublishOptions(@event);
         if (opt != null)
         {
             await _mqPublisher.PublishAsync(@event, this.PublishOptions.Topic, this.PublishOptions.MQProvider, publishType);
         }
     }
     catch (Exception ex)
     {
         this.Logger.LogError(ex, $"Publish {@event.TypeCode}.V{@event.Version} event failed");
     }
 }
Example #2
0
 public EventPublishModel(IEvent evt, string topic, string mqProviderName, MQPublishType publishType = MQPublishType.Asynchronous)
 {
     this.Event          = evt;
     this.Topic          = topic;
     this.MQProviderName = mqProviderName;
     this.Type           = publishType;
 }
Example #3
0
 public void WriteEventAsync(IList <IEvent <TStateKey> > events, MQPublishType publishType = MQPublishType.Asynchronous)
 {
     if (events == null || events.Count == 0)
     {
         throw new ArgumentNullException("WriteEventAsync event cannot be empty");
     }
     foreach (var e in events)
     {
         this.WriteEventAsync(e, publishType);
     }
 }
Example #4
0
        public void WriteEventAsync(IEvent <TStateKey> @event, MQPublishType publishType = MQPublishType.Asynchronous)
        {
            if (@event == null)
            {
                throw new ArgumentNullException("WriteEventAsync event cannot be empty");
            }
            @event.Version = State.NextVersion();
            @event.StateId = State.StateId;
            var model = new EventTransactionModel <TStateKey>(@event, publishType);

            this.WriteEventAsync(model);
        }
Example #5
0
        protected async virtual Task <bool> WriteAsync(IEvent <TStateKey> @event, MQPublishType publishType = MQPublishType.Asynchronous)
        {
            if (@event == null)
            {
                throw new ArgumentNullException("WriteAsync event cannot be empty");
            }

            this.IsBlockProcess();
            if (this.IsBeginTransaction)
            {
                throw new Exception("Do not process a single event in a transaction");
            }

            @event.Version = State.NextVersion();
            @event.StateId = State.StateId;
            //Storage event
            if (await this._eventSourcing.SaveAsync(@event))
            {
                try
                {
                    //Paly state
                    this.State.Player(@event);
                }
                catch (Exception ex)
                {
                    this.IsBlock = true;
                    throw ex;
                }
                //Publish event
                await this.PublishEventAsync(@event, publishType);

                //Save snapshot
                if (this._eventSourcing.Options.SnapshotOptions.SnapshotType == SnapshotType.Synchronous)
                {
                    await this._eventSourcing.SaveSnapshotAsync(this.State);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #6
0
        /// <summary>
        /// concurrent  write event
        /// </summary>
        /// <param name="event"><see cref="IEvent{TStateKey}"/></param>
        /// <param name="publishType">is to publish to MQ</param>
        /// <returns></returns>
        protected virtual Task <bool> ConcurrentWriteAsync(IEvent <TStateKey> @event, MQPublishType publishType = MQPublishType.Asynchronous)
        {
            if (@event == null)
            {
                throw new ArgumentNullException("ConcurrentWriteAsync event cannot be empty");
            }
            this.IsBlockProcess();
            var model = new EventTransactionModel <TStateKey>(@event, publishType);

            return(this._eventBufferBlock.SendAsync(model));
        }
Example #7
0
 public Task<bool> PublishAsync(IEvent evt, string topic, string mqProviderName, MQPublishType publishType = MQPublishType.Asynchronous)
 {
     EventPublishModel wrap = new EventPublishModel(evt, topic, mqProviderName, publishType);
     return this.PublishAsync(wrap);
 }
Example #8
0
 public static async Task PublishAsync(this IMQPublisher publisher, IList <IEvent> events, string topic, string mqProviderName, MQPublishType publishType = MQPublishType.Asynchronous)
 {
     if (events == null || events.Count == 0)
     {
         return;
     }
     foreach (var e in events)
     {
         await publisher.PublishAsync(e, topic, mqProviderName, publishType);
     }
 }
Example #9
0
 public static async Task PublishAsync(this IMQPublisher publisher, IList <IEvent> events, MQPublishType publishType = MQPublishType.Asynchronous)
 {
     if (events == null)
     {
         return;
     }
     foreach (var e in events)
     {
         await publisher.PublishAsync(e, publishType);
     }
 }
Example #10
0
        public static Task <bool> PublishAsync(this IMQPublisher publisher, IEvent @event, MQPublishType publishType = MQPublishType.Asynchronous)
        {
            var options = GetAttributeOptions(@event.GetType());

            if (options == null)
            {
                throw new Exception($"No eventPublishAttribute is marked for {@event.GetType().FullName} events");
            }
            return(publisher.PublishAsync(@event, options.Topic, options.MQProvider, publishType));
        }
Example #11
0
 public EventTransactionModel(IEvent <TStateKey> @event, MQPublishType publishType)
 {
     this.Event       = @event;
     this.PublishType = publishType;
 }