0
votes

I've been working on a project where I need Nservicebus to be hosted in IIS. I need the MVC3 webapplication to send a message, a nservicebus host should handle this message and then send back some sort of message to the webapplication.

the Async Pages example http://docs.particular.net/samples/web/asp-mvc-application/ shows one way of doing it. I can get this to work, however this does not fully furfill my requirements. I need an object to be returned from the handler, not just an int.

To get this to work i've tried setting up a host under IIS, in my Global.asax I've got this code:

Bus = Configure.WithWeb()                
               .DefineEndpointName("CQRS")
               .Log4Net()                   
               .DefaultBuilder()                
               .DisableTimeoutManager()                
               .XmlSerializer()
               .MsmqTransport()
                   .IsTransactional(true)
                   .PurgeOnStartup(false)
                   .InMemorySubscriptionStorage()
               .UnicastBus()              
                   .AllowSubscribeToSelf()
                   .ImpersonateSender(false)
                   .LoadMessageHandlers()  
                   .CreateBus().Start();  

my 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>

Sending messages with the Bus object works perfectly, a message appears in the "cqrs" queue. The handler within the webapplication however does not trigger. This is the code:

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));

    }
}

I'm sure I'm missing something small here but what am I doing wrong, why doesn't the handler get triggered while I can clearly see a message in the queue. Also on the Bus object I can see the handler being loaded.

2

2 Answers

1
votes

If you configure installer correctly in your fluent configuration then NSB sets the rights on the queue properly. http://andreasohlund.net/2012/01/26/installers-in-nservicebus-3-0/

0
votes

Ok, I think I figured it out, it seems that the queue's created by NSB dont have full access permissions for the IIS USER. I've set "full control" for everyone on each of the queue's and restarted IIS. Somehow it seems to work now