public Task <AsyncExecutedResult> PublishAsync(IMessage message)
 {
     return(queueProducer.ProduceAsync(subscriptionManager.GetQueueTopic(message), objectSerializer.Serialize(new QueueMessage
     {
         Content = objectSerializer.Serialize(message),
         Tag = message.GetTag()
     })));
 }
Beispiel #2
0
        EventStreamDescriptor ToStreamDescriptor(EventStream stream)
        {
            var eventContentMapping = new Dictionary <string, string>();

            foreach (var e in stream.Events)
            {
                eventContentMapping.Add(e.GetTag(), objectSerializer.Serialize(e));
            }

            return(new EventStreamDescriptor
            {
                AggregateRootId = stream.AggregateRootId,
                AggregateRootTypeName = stream.AggregateRootTypeName,
                CommandId = stream.CommandId,
                Events = objectSerializer.Serialize(eventContentMapping),
                Id = stream.Id,
                Timestamp = stream.Timestamp,
                Version = stream.Version
            });
        }
Beispiel #3
0
        public Task <AsyncExecutedResult> PublishStreamAsync(EventStream stream)
        {
            var events = new Dictionary <string, string>();

            foreach (var e in stream.Events)
            {
                events.Add(e.GetTag(), objectSerializer.Serialize(e));
            }

            return(queueProducer.ProduceAsync(
                       subscriptionManager.GetQueueTopic(stream.Events.First()),
                       objectSerializer.Serialize(new EventStreamMessage
            {
                AggregateRootId = stream.AggregateRootId,
                AggregateRootTypeName = stream.AggregateRootTypeName,
                CommandId = stream.CommandId,
                Events = events,
                Id = stream.Id,
                Timestamp = stream.Timestamp,
                Version = stream.Version
            })));
        }
Beispiel #4
0
        async Task PublishApplicationMessageAsync(ProcessingCommand processingCommand, IApplicationMessage applicationMessage)
        {
            var result = await Policy
                         .Handle <Exception>()
                         .OrResult <AsyncExecutedResult>(r => !r.Succeeded)
                         .WaitAndRetryForeverAsync(
                retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
                (delegateResult, retryCount, retryAttempt) => logger.LogError(delegateResult.Exception ?? delegateResult.Result.Exception, $"命令产生的应用消息发布失败,重试。 [CommandType = {processingCommand.Command.GetType()}, CommandId = {processingCommand.Command.Id}, ApplicationMessageType = {applicationMessage.GetType()}, ApplicationMessageId = {applicationMessage.Id}, ApplicationMessageRoutingKey = {applicationMessage.GetRoutingKey()}, RetryCount = {retryCount}, RetryAttempt = {retryAttempt}]"))
                         .ExecuteAsync(() => applicationMessagePublisher.PublishAsync(applicationMessage));

            if (result.Succeeded)
            {
                logger.LogDebug($"命令产生的应用消息发布成功。 [CommandType = {processingCommand.Command.GetType()}, CommandId = {processingCommand.Command.Id}, ApplicationMessageType = {applicationMessage.GetType()}, ApplicationMessageId = {applicationMessage.Id}, ApplicationMessageRoutingKey = {applicationMessage.GetRoutingKey()}]");
                await processingCommand.OnQueueProcessedAsync(CommandExecutedStatus.Succeeded, objectSerializer.Serialize(applicationMessage), applicationMessage.GetTag());
            }
            else
            {
                logger.LogDebug(result.Exception, $"命令产生的应用消息发布失败。 [CommandType = {processingCommand.Command.GetType()}, CommandId = {processingCommand.Command.Id}, ApplicationMessageType = {applicationMessage.GetType()}, ApplicationMessageId = {applicationMessage.Id}, ApplicationMessageRoutingKey = {applicationMessage.GetRoutingKey()}]");
            }
        }