0
votes

Perhaps I'm missing something here and this question is maybe the same as this one so sorry for any duplication.

I have an MVC4 site that quite happily Sends() commands to my NServiceBus server. I now want the same MVC site to be able to subscribe to IEvents Publish()ed from the same NServiceBus server. But I just can't get it to work.

Messages are being published from the server and are showing in MSMQ but I can't get the MVC site to pick them up.

Is this possible with NServiceBus 3.3.5? And if so, how do I have to set up my MVC site to make it work?

Thanks in advance!

Edit: Here's the config I have in the MVC app:

Configure.With()
            .Log4Net()
            .StructureMapBuilder()
            .MsmqTransport()
            .IsTransactional(false)
            .PurgeOnStartup(false)
            .UnicastBus()
            .LoadMessageHandlers()
            .ImpersonateSender(false)
            .JsonSerializer()
            .CreateBus()
            .Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());

I don't have an EndpointConfig class that implements the IConfigureThisEndpoint or and AsA_ interfaces. I've tried adding one but it never gets called and I can't work out what the host would be or how to start the NServiceBus host application from the web app. Or even what context the host would run under if the code sits inside IIS (if that makes sense!).

1
why do you need to listen to events?Chris Bednarski
Maybe my terminology is wrong, but what I want to achieve is: Multiple web servers each with separate cache cache some data. Another process somewhere else in the enterprise changes some data through and nServiceBus powered application layer. I want that application to broadcast a 'this piece of data has changed' message/event so that all interested parties (my web sites in this case) can react if they need to. I know there are 100 ways to solve this cache update problem, but I like clean ness of this solution (if it's possible).stush
Does your site have its own queue? Are you able to publish messages to any other endpoint?Chris Bednarski

1 Answers

0
votes

My guess is you're missing the .LoadMessageHandlers() line in your fluent config after .UnicastBus() - that's the most common error that leads to self-hosted applications not processing messages sent to them.

If that's not the case, add your fluent config block to your question and we'll take a look.

Edit: After fluent config posted

My next guess is that you're declaring your serializer too late. The .UnicastBus() step is one of the last stops before "Let's start this thing!" I'm thinking perhaps by the time you've hit this point, the config has made the assumption you're going with the default XmlSerializer. Could you try moving the serializer line to right after .StructureMapBuilder() and see if that works better?

If that doesn't work I might consider using the .DefaultBuilder() momentarily just to rule out an problem with your IoC container.

In regards to your other comments, a self-hosted bus will never have an EndpointConfig. That's a pointer for endpoints hosted by the NServiceBus.Host.exe only.

I also suppose it's not completely obvious where you're calling this fluent config from. This code needs to be called once when the webapp is started up - usually from the application start method in the Global.asax. Because the webapp is in control, there's no automatic assembly scanning to find and wire up your NServiceBus pipeline like in the NServiceBus Host.