views:

90

answers:

1

Using the pub/sub sample i managed to get multiple instances of the same console app to read all messages sent from the publisher. What I did whas this:

namespace Subscriber1

{ public class EndpointConfig : IConfigureThisEndpoint, AsA_Server { }

public class OverrideInputQueue : IWantCustomInitialization
{
    public void Init()
    {
        Configure
            .Instance
            .Configurer
            .ConfigureComponent<MsmqTransport>(NServiceBus.ObjectBuilder.ComponentCallModelEnum.None)
            .ConfigureProperty(p => p.InputQueue, Guid.NewGuid());


    }
}

}

How do i setup a wpf app to have multiple instances all read notifications from the publisher??

Using the code above doesn't do it for me because those lines of code will never be hit.

In my wpf app i reference the NServiceBus host, I add this to the windows code behind:

        public Window1()
    {
        InitializeComponent();
        this.Title = App.AppId.ToString();

        var bus = NServiceBus.Configure.With()
                .DefaultBuilder()
                .XmlSerializer()
                .MsmqTransport()
                    .IsTransactional(true)
                    .PurgeOnStartup(false)
                .UnicastBus()
                    .ImpersonateSender(false)
                    .LoadMessageHandlers()
                .CreateBus()
                .Start();
    }

and I put the I "OverrideInputQueue : IWantCustomInitialization"-part in my endpoint config.

But as I said that part never gets hit. The result is that when you start up two instances of the app, they take turns in picking up the message sent from the publisher. I want both instances to receive ALL messages.

What have I missed?

/Johan

+1  A: 

The problem is that IWantCustomInitialization is only relevant when using the NServiceBus.Host.exe process. What you need to do in your initialization code is this:

        var bus = NServiceBus.Configure.With() 
            .DefaultBuilder() 
            .XmlSerializer() 
            .MsmqTransport() 
                .IsTransactional(true) 
                .PurgeOnStartup(false) 
            .RunCustomAction( () => Configure.Instance.Configurer.ConfigureProperty<MsmqTransport>(p => p.InputQueue, Guid.NewGuid()) )
            .UnicastBus() 
                .ImpersonateSender(false) 
                .LoadMessageHandlers() 
            .CreateBus() 
            .Start(); 
Udi Dahan
Thanks! I'll try that ASAP.
Johan Zell