0
votes

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
You've created a competing consumer. Any reason you only want one queue and not one per subscriber?Adam Fyles
Exactly. That is the problem. Why doesn't the Init method of "OverrideInputQueue : IWantCustomInitialization" class execute. It does in my console app and every instance gets their uniqeu queue. So there is something with my setup in wpf that's FUBAR. I just don't know what.Johan Zell

1 Answers

1
votes

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