Duncan
Duncan

Reputation: 10291

NServiceBus - put message back on bus

I have a bus endpoint that processes a message, however I now want to put another message back on to the bus inside this handler.

To do this I need to get a reference to the bus.

However if I try the following:

public class ServerEndpoint: IWantToRunAtStartup
{
    public static IBus Bus { get; set; }

    public void Run()
    {
        int x = 5;

        Bus = NServiceBus.Configure.With()
            .DisableTimeoutManager()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();

    }

    public void Stop()
    {
    }
}

Then I get all sort of config errors, even if I put the Unicast and Msmq Configs in the app.config.

Could anyone provide me with pointers, I'm hoping this is a fairly straightforward mistake!!

Thanks

Duncan

EDIT: This is on the server. The thing that is confusing me is that the bus gets configured on the web app using the above code, in the global.asax App_Start() method. But when trying to do this in the ServerEndpoint (the actual 'bus' dll, run inside the host) this doesn't work.

Upvotes: 0

Views: 255

Answers (2)

Duncan
Duncan

Reputation: 10291

Thanks for all the feedback - I was trying to run before I could walk.

By the looks of things, to send a message to another endpoint, I need to set up a different assembly (ServiceBus.Host).

The Bus is created automatically using DI, so this wasn't the problem after all.

I watched the excellent Pluralsight videos by Andreas Ohlund (http://pluralsight.com/training/Courses/TableOfContents/nservicebus) and followed the examples he built here (See BusStop - Billing Take 2)

Upvotes: 0

Related Questions