我正在尝试设置 MassTransit 请求/响应方案。问题是消息永远不会到达消费者。我在 PublishRequest 上收到“等待响应超时”错误。日志文件中没有显示其他错误。正在 msmq 中创建消息。
异常信息:
异常类型:TargetInvocationException 异常消息:调用的目标已抛出异常。在 System.RuntimeTypeHandle.CreateInstance(RuntimeType 类型,Boolean publicOnly,Boolean noCheck,Boolean& canBeCached,RuntimeMethodHandleInternal& ctor,Boolean& bNeedSecurityCheck)在 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache,StackCrawlMark 和 stackMark)在 System.RuntimeType.CreateInstanceDefaultCtor (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark & stackMark)
在 System.Activator.CreateInstance(Type type, Boolean nonPublic) 在 System.Activator.CreateInstance(Type type) 在 System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)等待响应超时,RequestId: 08cfa243-4a88-ba3a-20cf-307f54910000 at MassTransit.RequestResponse.RequestImpl
1.Wait() in d:\BuildAgent-03\work\8d1373c869590c5b\src\MassTransit\RequestResponse\RequestImpl.cs:line 124 at MassTransit.RequestResponseExtensions.PublishRequest[TRequest](IServiceBus bus, TRequest message, Action
1 configureCallback) in d:\BuildAgent-03\work\8d1373c869590c5b\src\MassTransit\RequestResponseExtensions.cs:line 31 at Producer。 c:\Users\rick\Documents\Visual Studio 2012\Projects\ConsumerTest1\Producer.Website\Controllers\AccountController.cs:line 56 中的 Website.Controllers.AccountController..ctor()
生产者设置:
_bus = ServiceBusFactory.New(sbc =>
{
sbc.UseMsmq();
sbc.VerifyMsmqConfiguration();
sbc.UseMulticastSubscriptionClient();
sbc.SetNetwork("Test");
sbc.ReceiveFrom("msmq://localhost/consumer_test_1");
});
生产者发送消息:
var message = new AccountNewMessage()
{
CorrelationId = CombGuid.Generate(),
UserName = “blah blah”,
Password = “yada yada”
};
this._bus.PublishRequest(message, r =>
{
r.SetTimeout(30.Seconds());
r.Handle<AccountNewMessageResponse>(m =>
{
var response = m;
});
});
消费者设置:
this.bus = ServiceBusFactory.New(sbc =>
{
sbc.UseMsmq();
sbc.VerifyMsmqConfiguration();
sbc.UseMulticastSubscriptionClient();
sbc.SetNetwork("Test");
sbc.ReceiveFrom("msmq://localhost/consumer_test_2");
sbc.Subscribe(subs => subs.Instance(new AccountNewMessageConsumer()));
});
消费者:
public class AccountNewMessageConsumer : Consumes<AccountNewMessage>.Context
{
public void Consume(IConsumeContext<AccountNewMessage> context)
{
context.Respond(new AccountNewMessageResponse()
{
CorrelationId = context.Message.CorrelationId,
ErrorCode = "1",
UserId = new Random().Next(1, 10000).ToString()
});
}
}
留言:
[Serializable]
public class AccountNewMessage : CorrelatedBy<Guid>
{
public Guid CorrelationId { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}
[Serializable]
public class AccountNewMessageResponse : CorrelatedBy<Guid>
{
public Guid CorrelationId { get; set; }
public string UserId { get; set; }
public string ErrorCode { get; set; }
}
我究竟做错了什么?谢谢你。