private Task PublishMessage(TransportOperation o)
        {
            var publishOptions = new PublishOptions();

            publishOptions.SetMessageId(o.MessageId.ToString());
            return(_messageSession.Publish(o.Message, publishOptions));
        }
    public static Task PublishWithId <T>(this IMessageHandlerContext messageSession, T message, string id) where T : IEvent
    {
        var options = new PublishOptions();

        options.SetMessageId(id);
        return(messageSession.Publish(message, options));
    }
Example #3
0
    public static Task PublishWithId(this IMessageHandlerContext messageSession, object message, string id)
    {
        var options = new PublishOptions();

        options.SetMessageId(id);
        options.RequireImmediateDispatch();
        return(messageSession.Publish(message, options));
    }
        public void GetMessageId_Should_Return_Defined_Id()
        {
            const string expectedMessageID = "expected message id";
            var options = new PublishOptions();
            options.SetMessageId(expectedMessageID);

            Assert.AreEqual(expectedMessageID, options.GetMessageId());
        }
        public void GetMessageId_Should_Return_Defined_Id()
        {
            const string expectedMessageID = "expected message id";
            var          options           = new PublishOptions();

            options.SetMessageId(expectedMessageID);

            Assert.AreEqual(expectedMessageID, options.GetMessageId());
        }
Example #6
0
        public async Task PublishUserDeleted(Guid id)
        {
            var options = new PublishOptions();
            var @event  = new UserDeleted
            {
                Id = id
            };

            options.SetMessageId(id.ToString());

            await _endpoint.Publish(@event, options);
        }
Example #7
0
        /// <summary>
        /// customize endpointInstance.Publish to send a custome UniqueId to be able to save the UniqueId in LocalIntegrationEvent
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task <string> Publish(object message)
        {
            var messageId = Guid.NewGuid();
            var options   = new PublishOptions();

            options.SetMessageId(messageId.ToString());

            await endpointInstance.Publish(message, options)
            .ConfigureAwait(false);

            return(messageId.ToString());
        }
Example #8
0
        public async Task PublishUserUpdated(Guid id, string login, string firstName, string lastName)
        {
            var options = new PublishOptions();
            var @event  = new UserUpdated
            {
                Id        = id,
                Login     = login,
                FirstName = firstName,
                LastName  = lastName
            };

            options.SetMessageId(id.ToString());

            await _endpoint.Publish(@event, options);
        }
Example #9
0
        public void When_publishing_with_user_defined_message_id_should_set_defined_id_and_header()
        {
            const string expectedMessageID = "expected message id";

            var publishPipeline   = new FakePipeline <IOutgoingPublishContext>();
            var messageOperations = CreateMessageOperations(publishPipeline: publishPipeline);

            var publishOptions = new PublishOptions();

            publishOptions.SetMessageId(expectedMessageID);
            messageOperations.Publish <MyMessage>(new FakeRootContext(), m => { }, publishOptions);

            Assert.AreEqual(expectedMessageID, publishPipeline.ReceivedContext.MessageId);
            Assert.AreEqual(expectedMessageID, publishPipeline.ReceivedContext.Headers[Headers.MessageId]);
        }
Example #10
0
        public static Task SendDuplicates <TMessage>(IMessageSession context, TMessage message, int totalCount)
        {
            var duplicatedMessageId = Guid.NewGuid().ToString();

            var tasks = Enumerable.Range(0, totalCount)
                        .Select(i =>
            {
                var options = new PublishOptions();
                options.SetMessageId(duplicatedMessageId);
                log.Info($"Sending Dupe Event with MessageId= {duplicatedMessageId}");
                return(context.Publish(message, options));
            });

            return(Task.WhenAll(tasks));
        }
Example #11
0
        public async Task <Guid> Publish(object message, Guid?messageId)
        {
            if (messageId == null)
            {
                messageId = Guid.NewGuid();
            }

            var options = new PublishOptions();

            options.SetMessageId(messageId.ToString());

            await endpointInstance.Publish(message, options)
            .ConfigureAwait(false);

            return(messageId.Value);
        }
Example #12
0
    public override async Task Invoke(IIncomingLogicalMessageContext context, Func <Task> next)
    {
        var dbContext = new OrdersDataContext();
        ProcessedMessage processedMessage;

        using (var dbContextTransaction = dbContext
                                          .Database.BeginTransaction())
        {
            processedMessage = await dbContext
                               .ProcessedMessages
                               .FirstOrDefaultAsync(m => m.MessageId == context.MessageId);

            if (processedMessage == null)
            {
                processedMessage = new ProcessedMessage {
                    MessageId = context.MessageId
                };
                dbContext.ProcessedMessages.Add(processedMessage);

                await dbContext.SaveChangesAsync()
                .ConfigureAwait(false);

                context.Extensions.Set(dbContext);

                await next().ConfigureAwait(false); //Process

                var serializedMessages = JsonConvert.SerializeObject(dbContext.OutgoingMessages, serializerSettings);
                processedMessage.OutgoingMessages = serializedMessages;

                await dbContext.SaveChangesAsync()
                .ConfigureAwait(false);
            }

            dbContextTransaction.Commit();
        }

        var outgoingMessages =
            JsonConvert.DeserializeObject <List <OutgoingMessage> >(processedMessage.OutgoingMessages, serializerSettings);

        foreach (var outgoingMessage in outgoingMessages)
        {
            var publishOptions = new PublishOptions();
            publishOptions.SetMessageId(outgoingMessage.MessageId);
            await context.Publish(outgoingMessage.Payload, publishOptions);
        }
    }
        public async Task Handle(ProcessClientOutboxMessageCommandV2 message, IMessageHandlerContext context)
        {
            var clientOutboxMessageId = Guid.Parse(context.MessageId);
            var clientOutboxMessage   = await _clientOutboxStorage.GetAsync(clientOutboxMessageId, context.SynchronizedStorageSession);

            var tasks = clientOutboxMessage.TransportOperations.Select(o =>
            {
                var publishOptions = new PublishOptions();

                publishOptions.SetMessageId(o.MessageId.ToString());

                return(context.Publish(o.Message, publishOptions));
            });

            await Task.WhenAll(tasks);

            await _clientOutboxStorage.SetAsDispatchedAsync(clientOutboxMessage.MessageId, context.SynchronizedStorageSession);
        }