tags:

views:

34

answers:

1

I'm just starting out with NServiceBus and have updated the PubSub sample to work with .NET 4.0 Framework. That's working perfectly ok. This runs one publisher and two subscribers within the "NServiceBus.Host.exe" environment - so it is that which takes responsibility for setting up an instance of the Bus and doing any relevant subscriptions. That's all working fine (as you'd expect) but I'm now trying to move the publisher out of being run within "NServiceBus.Host.exe" into it's own console application (eventually I would like to publish messages from a website so this seems a good small step in that direction).

If I start the 3 projects (my console app, Sub1 and Sub2) it creates 5 msmq on my local machine, but instead of the endpoint.config...subscriptions Q, it creates a generic "nservicebus_subscriptions" Q. If I enable journals, I see that the MyPublisherInputQueue has three (processed) completion messages with an errorcode 0, whilst the subscriber1inputqueue and subscriber2inputqueue each have one. This all seems good, but if I then publish messages, the publisher doesn't appear to throw any errors, but no messages make it as far as the subscribers (they just sit waiting for a message). Also no messages appear in either the new message or journal for any of the MQs.

I'm obviously missing some step(s) - Is the console application not opening itself up for subscriptions? If so, what steps are needed to do that? What steps am I missing that run when you host the publisher in the nservicebus.host.exe?

To create the console application I've done the following:

  1. Within the pubsub solution, created a console application.
  2. Added references in the console application to mymessages, nservicebus.dll and nservicebus.core.dll
  3. From the existing pub code and example on the NServiceBus website, added following code to "Main()"

        IBus Bus = Configure.With()
                        .Log4Net()
                        .DefaultBuilder()
                        .MsmqSubscriptionStorage()
                        .XmlSerializer()
                        .MsmqTransport()
                        .UnicastBus()
                            .LoadMessageHandlers()
                        .CreateBus()
                        .Start();
    
    
    
    bool publishIEvent = true;
    do
    {
        Console.ReadLine();
    
    
        var eventMessage = publishIEvent ? Bus.CreateInstance<IEvent>() : new EventMessage();
    
    
        eventMessage.EventId = Guid.NewGuid();
        eventMessage.Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null;
        eventMessage.Duration = TimeSpan.FromSeconds(99999D);
    
    
        Bus.Send(eventMessage);
    
    
        Console.WriteLine("Published event with Id {0}.", eventMessage.EventId);
    
    
    } while (true);
    
  4. Created an app.config for the new console application using the contents of the existing "publisher" app.config.

  5. Added "NServiceBus.Integration" to command line arguments for console application project.

+1  A: 

If you look at your logs, it is likely that NServiceBus is telling you that you need to have your publisher be configured to be transactional. The way to do that is to include .IsTransactional(true) after .MsmqTransport().

Udi Dahan
Fantastic, that worked - Thank you. It's the 1st time I've come across Log4Net too so definitely encountering a vertical learning curve - hopefully I'll get to a point soon that I won't feel like a complete beginner.
Paul Hadfield
If your goal is to set up webapp to send messages I would go directly to attempting that. Web applications should not Publish() messages anyway, just Send(), so keeping all your publishers running in the NServiceBus.Host.exe is probably easier. Then your webapp does not require subscription storage, etc.
David
@David: So the "correct" model is for 1+ web applications (possibly load balanced?) to send messages to a centralised message handler, which then publishes on? Sounds like I have to spend some time this weekend looking into "Send".
Paul Hadfield
Exactly! A fairly long winded discussion of this can be found here: http://tech.groups.yahoo.com/group/nservicebus/message/7717
David