我有密码,
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
1条答案
按热度按时间wwodge7n1#
事务发件箱设计用于在应用程序执行数据库操作并生成消息时使用。MassTransit不负责使用Bus Outbox将更改提交到数据库-它只是将记录添加到DbContext,并且由应用程序调用
SaveChangesAsync
和/或提交整个事务。这与消费者发件箱不同,后者的整个交易由MassTransit管理。