rabbitmq 发件箱发布在一个控制器中工作,而在另一个控制器中不工作

piok6c0g  于 2023-03-12  发布在  RabbitMQ
关注(0)|答案(1)|浏览(165)

我有密码,

await _publishEndpoint.Publish(myMessage);

相同的代码插入到一个控制器的InboxState/OutboxState/OutboxMessage中,但在另一个控制器中不起作用。
即使我使用了SQL分析器,它显示没有发出查询?
你为什么要这样?
看源代码看起来像SaveChanges没有调用?

var outboxMessage = new OutboxMessage
            {
                MessageId = context.MessageId.Value,
                ConversationId = context.ConversationId,
                CorrelationId = context.CorrelationId,
                InitiatorId = context.InitiatorId,
                RequestId = context.RequestId,
                SourceAddress = context.SourceAddress,
                DestinationAddress = context.DestinationAddress,
                ResponseAddress = context.ResponseAddress,
                FaultAddress = context.FaultAddress,
                SentTime = context.SentTime ?? now,
                ContentType = context.ContentType?.ToString() ?? context.Serialization.DefaultContentType.ToString(),
                Body = body.GetString(),
                InboxMessageId = inboxMessageId,
                InboxConsumerId = inboxConsumerId,
                OutboxId = outboxId
            };

            if (context.TimeToLive.HasValue)
                outboxMessage.ExpirationTime = now + context.TimeToLive;

            if (context.Delay.HasValue)
                outboxMessage.EnqueueTime = now + context.Delay;

            outboxMessage.Headers = deserializer.SerializeDictionary(context.Headers.GetAll());

            if (context is TransportSendContext<T> transportSendContext)
            {
                var properties = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

                transportSendContext.WritePropertiesTo(properties);
                outboxMessage.Properties = deserializer.SerializeDictionary(properties);
            }

            await collection.AddAsync(outboxMessage, context.CancellationToken).ConfigureAwait(false);

https://github.com/MassTransit/MassTransit/blob/bda1932f1851aaa102062681f1b8d6fbff9a4871/src/Persistence/MassTransit.EntityFrameworkCoreIntegration/EntityFrameworkCoreIntegration/EntityFrameworkOutboxExtensions.cs#L59

wwodge7n

wwodge7n1#

事务发件箱设计用于在应用程序执行数据库操作并生成消息时使用。MassTransit不负责使用Bus Outbox将更改提交到数据库-它只是将记录添加到DbContext,并且由应用程序调用SaveChangesAsync和/或提交整个事务。
这与消费者发件箱不同,后者的整个交易由MassTransit管理。

相关问题