请求始终获取RequestTimeoutException

时间:2018-10-05 13:21:51

标签: request timeout masstransit

我正在使用ASP.NET Core + Simple Injector和MassTransit v5.1.5。每次尝试使用请求/响应时,我都会收到一个RequestTimeoutException。

{
            var host = c.Host(new Uri("rabbitmq://localhost/"), h =>
            {
                h.Username("guest");
                h.Password("guest");
            });

            c.ReceiveEndpoint(host, "test_sample_injector", ep =>
            {
                // the prefetch count is important for the performance
                ep.PrefetchCount = 16;

                // ep.LoadFrom requires the service provider which should be build on the top of services
                // and would load all implementations of IConsumer<T> that were added as scoped above
                ep.LoadFrom(container);

                // the endpoint needs to be binded to a class/interface otherwise the messages are going into
                // _skipped queue
                ep.Bind<SampleMessage>();

                EndpointConvention.Map<SampleMessage>(ep.InputAddress);

                ep.Handler<IMessage>(context =>
                {
                    // the handler is called before the consumer
                    return Console.Out.WriteLineAsync($"Received: from handler!");
                });
            });
        };

这是我使用的RabbitMQ配置。我对消费者进行了以下容器注册:

        container.Register<IConsumer<SampleMessage>, SampleMessageConsumer>(Lifestyle.Singleton);

消费者看起来像:

  public class SampleMessageConsumer : IConsumer<SampleMessage>
{
    public async Task Consume(ConsumeContext<SampleMessage> context)
    {
        await context.RespondAsync<DoneSampleMessage>(
            new DoneSampleMessage
            {
                Result = context.Message.Text.ToUpperInvariant()
            });
    }
}

我打的电话是:

[HttpGet]
        public async Task<ActionResult<IEnumerable<string>>> Get()
        {
            var r = await _msgSender.Request<SampleMessage, DoneSampleMessage>(
                new SampleMessage() { Text = "[Simple Injector]Hello World!" });


            return new string[] { "value1", "value2" };
        }

所有处理程序和使用者都被调用,但是RespondAsync似乎不起作用。我有一个MessageSender,其中有Request方法:

 public Task<TResponse> Request<TRequest, TResponse>(TRequest r)
        where TRequest : class
        where TResponse : class
    {
        var client = new MessageRequestClient<TRequest, TResponse>(
            MessageBus,
            _serviceAddress,
            _timeout);

        return client.Request(r);
    }

我也已经启动了公共汽车。

那么有什么想法可以找到此RequestTimeoutException的原因,或者至少如何解决此问题?

0 个答案:

没有答案