我正在从客户端向服务器发送4条消息。在每条消息上,服务器处理数据并使用context.Respond
回复客户端。
即使客户端按预期收到所有4个响应,在控制台窗口中我也可以看到以下几个实例:
MassTransit.Pipeline.Filters.RescueReceiveContextFilter 错误:0:抢救异常,System.NullReferenceException:Object 引用未设置为对象的实例。在 MassTransit.Pipeline.Filters.HandlerMessageFilter`1> - 发送> d__5.MoveNext()
---从抛出异常的先前位置开始的堆栈跟踪结束---
接收回复所涉及的代码是:
Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var host = cfg.Host(new Uri(MqUri), h =>
{
h.Username(MqUserName);
h.Password(MqPassword);
});
//Start receiving from
cfg.ReceiveEndpoint(host, MqQueueName, e =>
{
//Handle response from server
e.Handler<IResonseToNotificationMessage>(ctx =>
{
//Forward the response
OnResponse?.Invoke(this,new ResponseEventArg()
{ResponseMessage = ctx.Message});
return null;
});
});
});
我正在使用Masstransit v3.2.0。什么可能导致此错误?
答案 0 :(得分:0)
因此,处理程序必须返回一个Task,并且您将返回null
。试试这个:
//Start receiving from
cfg.ReceiveEndpoint(host, MqQueueName, e =>
{
//Handle response from server
e.Handler<IResonseToNotificationMessage>(ctx =>
{
//Forward the response
OnResponse?.Invoke(this,new ResponseEventArg()
{ResponseMessage = ctx.Message});
return Task.FromResult(0);;
});
});