NserviceBus托管在IIS问题
问题描述:
我一直在一个项目,我需要Nservicebus托管在IIS中。 我需要MVC3的网络应用程序发送消息,nservicebus主机应该处理这个消息 ,然后发送一些消息给web应用程序。NserviceBus托管在IIS问题
异步页示例http://docs.particular.net/samples/web/asp-mvc-application/ 显示了一种方法。我可以得到这个工作,但是这并不完全满足我的要求。我需要一个从处理程序返回的对象,而不仅仅是一个int。
为了得到这个工作,我已经试过设置IIS下的宿主,在我的Global.asax我有这样的代码:
Bus = Configure.WithWeb()
.DefineEndpointName("CQRS")
.Log4Net()
.DefaultBuilder()
.DisableTimeoutManager()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.InMemorySubscriptionStorage()
.UnicastBus()
.AllowSubscribeToSelf()
.ImpersonateSender(false)
.LoadMessageHandlers()
.CreateBus().Start();
我的web.config:
<MessageForwardingInCaseOfFaultConfig ErrorQueue="CQRS.error" />
<MsmqTransportConfig NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="" TimeoutManagerAddress="CQRS.timeouts">
<MessageEndpointMappings>
<add Messages="Nokavision.InvoiceProcessing.CQRS.Messages" Endpoint="CQRS" />
<add Messages="NServiceBus.Scheduling.Messages.ScheduledTask" Endpoint="CQRS" />
</MessageEndpointMappings>
</UnicastBusConfig>
使用Bus对象发送消息的过程非常完美,消息出现在“cqrs”队列中。 然而,web应用程序中的处理程序不会触发。这是代码:
public class UpdateInkoopFactuurAlgemeenHandler : IHandleMessages<UpdateInkoopFactuurAlgemeenCommand>
{
public IBus Bus { get; set; }
public void Handle(UpdateInkoopFactuurAlgemeenCommand message)
{
P2PEntities entities = new P2PEntities();
var factuur = (from f in entities.Documenten.OfType<InkoopFactuur>()
where f.DocumentId == message.DTO.DocumentId
select f).FirstOrDefault();
if (factuur != null)
{
factuur.FactuurNummer = message.DTO.FactuurNummer;
entities.SaveChanges();
}
//Bus.Return(new UpdateInkoopFactuurAlgemeenResponse(message.DTO.ClientConnectionId));
}
}
我敢肯定,我失去了一些东西在这里小,但是我在做什么错,为什么不处理被触发,而我可以清楚地看到队列中的消息。 同样在Bus对象上,我可以看到正在加载的处理程序。
答
好吧,我想我想通了,似乎由NSB创建的队列没有IIS用户的完全访问权限。我已经为每个队列的每个人设置了“完全控制”,并重新启动了IIS。不知怎的,它似乎现在工作
答
如果你在流利的配置正确配置安装程序,然后NSB正确设置队列的权利。 http://andreasohlund.net/2012/01/26/installers-in-nservicebus-3-0/