我和RabbitMQ一起使用MassTransit。
我在网站上更改了经典示例:
这样:
x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ServiceQueueName"],
e => { e.Consumer<RequestConsumer>(); });
与
var consumer = new RequestConsumerT<string, string>(request =>
{
return "here it is " + request;
}
);
x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ServiceQueueName"],
e => { e.Instance(consumer); });
我正在使用RequestConsumerT类作为消费者:
public class RequestConsumerT<TRequest, TResponse> :
IConsumer<TRequest>
where TRequest: class
where TResponse : class
{
Func<TRequest, TResponse> _implementation;
public RequestConsumerT(Func<TRequest, TResponse> implementation)
{
_implementation = implementation;
}
public async Task Consume(ConsumeContext<TRequest> context)
{
//await context.RespondAsync<TResponse>(_implementation.Invoke(context.Message));
context.Respond<TResponse>(_implementation.Invoke(context.Message));
}
然后,当我提出请求时,消费者没有回答。 我的代码出了什么问题,好吗?
谢谢
这是我得到的错误:
System.AggregateException:发生了一个或多个错误。 ---&GT; MassTransit.RequestTimeoutException:超时等待响应,RequestId:b8ea0000-d435-8cdc-039a-08d3f41435b2
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在MassTransit.MessageRequestClient 2.<Request>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在Evolve.Messaging.Brokers.MassRabbitConnection。&lt;&gt; c__DisplayClass10 2.<<Request>b__d>d__12.MoveNext() in g:\src\Evolve.Messaging\Evolve.Messaging\Brokers\MassRabbitConnection.cs:line 198
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at Evolve.Messaging.Brokers.MassRabbitConnection.Request[TRequest,TResponse](TRequest request, String serviceName) in g:\src\Evolve.Messaging\Evolve.Messaging\Brokers\MassRabbitConnection.cs:line 203
at ConsoleApplication1.Program.Main(String[] args) in g:\src\Evolve.Messaging\ConsoleApplication1\Program.cs:line 47
---> (Inner Exception #0) MassTransit.RequestTimeoutException: Timeout waiting for response, RequestId: b8ea0000-d435-8cdc-039a-08d3f41435b2
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MassTransit.MessageRequestClient
2.d__6.MoveNext()
---从抛出异常的先前位置开始的堆栈跟踪结束---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()
at Evolve.Messaging.Brokers.MassRabbitConnection.<>c__DisplayClass10
2.&lt; b__d&gt; d__12.MoveNext()在g:\ src \ Evolve.Messaging \ Evolve.Messaging \ Brokers \ MassRabbitConnection.cs:第198行&lt; ---
这里有一些Rabbitmq经理的截图: