我们正在将Masstransit与请求/响应模式结合使用,如此处所述:http://masstransit-project.com/MassTransit/usage/request-response.html
由于某种原因,当使用本地主机初始化总线时,我会使用context.RespondAsync方法在响应端收到MassTransit.EndpointNotFoundException。
使用实际IP初始化总线后,它工作正常,没有任何异常。
我们还将总线与其他通过localhost初始化的masstransit模式一起使用,没有任何问题。
我们尝试在请求侧同时使用Request和GetResponse模式,认为可能存在问题根源,但没有成功。
以下是消费者代码的“响应”端,它在RespondAsync上生成异常:
public override async Task Consume(ConsumeContext<IImageRequest> context)
{
var msg = context.Message;
try
{
var image = GetImage(msg.Id);
await context.RespondAsync<IImageResult>(new
{
msg.Id,
AImage = image
});
}
catch (Exception e)
{
Logger.Instance.Error($"{e}");
}
}
以下是请求方:
Task.Run(async () =>
{
var reqResClient =
BusControl.GetBusControl.CreateRequestClient<IImageRequest, IImageResult>("requestimage");
var req = new ImageRequest(msg.Id);
var response = await reqResClient.Request(req);
}).Wait();
公交车初始化代码:
_bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Durable = true;
_host = cfg.Host(HostName, port, VirtualHost, h =>
{
h.Username(UserName);
h.Password(Password);
});
cfg.ReceiveEndpoint(host, subscriber.QueueName, ep =>
{
ep.Durable = !subscriber.AutoDelete;
ep.AutoDelete = subscriber.AutoDelete;
ep.Instance(subscriber.Consumer);
if (subscriber.PrefetchCount.HasValue)
ep.PrefetchCount = subscriber.PrefetchCount.Value;
if (subscriber.ConcurrencyLimit.HasValue)
ep.UseConcurrencyLimit(subscriber.ConcurrencyLimit.Value);
});
cfg.Message<T>(x =>
{
x.SetEntityName(entityName);
});
});
public void Start()
{
if (_state == BusState.NotInitialized)
throw new InvalidOperationException("Cannot start bus. Bus is not initialized");
_bus?.Start();
_state = BusState.Started;
}
我想知道是否有解决方案?还是已知问题?
谢谢