使用massTransit(8.0.8)后,我收到以下错误:
“RoutingSlipCompleted”不包含“GetVariable”的定义 以及最好的扩展方法重载 'RoutingSlipEventExtensions.GetVariable(ConsumeContext, string, Guid)' 需要类型的接收者 '消费上下文' 这是我的代码:
using MassTransit;
using MassTransit.Courier.Contracts;
using MassTransit.Courier;
public class CheckInventoriesConsumer: IConsumer<ICheckInventoryRequest>
, IConsumer<RoutingSlipCompleted>
, IConsumer<RoutingSlipFaulted>
{
private readonly IEndpointNameFormatter _formatter;
public CheckInventoriesConsumer(IEndpointNameFormatter formatter)
{
_formatter = formatter;
}
public async Task Consume(ConsumeContext<ICheckInventoryRequest> context)
{
var routingSlip = CreateRoutingSlip(context);
await context.Execute(routingSlip);
}
private RoutingSlip CreateRoutingSlip(ConsumeContext<ICheckInventoryRequest> context)
{ // lot of code here
}
public async Task Consume(ConsumeContext<RoutingSlipCompleted> context)
{
// error is here
context.Message.GetVariable<Guid>(nameof(ConsumeContext.RequestId));
throw new NotImplementedException();
}
}
它不会从
GetVariable
找到MassTransit.Courier
方法,并且我遇到了这个错误。
正如您根据您的评论已经发现的:
context.GetVariable<Guid>(nameof(ConsumeContext.RequestId));
是正确的解决方案。
MassTransit 版本 8 具有更广泛的序列化支持,并且需要
SerializationContext
(来自 ConsumeContext
)来正确反序列化路由滑动事件中的变量。