SzymonPobiega / NServiceBus.Router

Cross-transport, cross-site and possibly cross-cloud router component for NServiceBus
MIT License
5 stars 10 forks source link

MSMQ / ASB subscription duplicate events #35

Closed rawk01 closed 4 years ago

rawk01 commented 4 years ago

Hi there,

I've been playing around with the router component, in preparation for a piece of migration work I'm working on.

At the moment we have an MSMQ on premise solution, but newer components are coming on board using ASB.

I wanted to use the router the route commands sent from the MSMQ side of things into ASB to be processed there, and then also to route events published at the MSMQ side of things into ASB for processing.

I have been prototyping the solution (based on the mixedtransport solution), commands work great - I send one, it turns up for processing in my Azure Service Bus, all great. But when I try to deal with events though, when I publish an event in the MSMQ side of things, I always end up with exactly two copies of the event in ASB.

I'm at the point now where I think I'm either missing something obvious (or being stupid!) :)

I popped the subscription storage for the router into a SQL db table so I could just look at it, and it looks fine to me.

Any thoughts?

SzymonPobiega commented 4 years ago

Which version of the ASB transport and which topology do you use?

rawk01 commented 4 years ago

I'm using Nservicebus.Transport.AsuzreServiceBus.AzureServiceBusTransport (not the legacy one).

I've not specified a topology - so I'm guessing the ForwardingTopology is being used. In the meantime I have enabled the Outbox functionality which means I'm no longer seeing the duplicate events.

SzymonPobiega commented 4 years ago

@rawk01 I'll take a look. The new transport indeed does not have the concept of topology but it uses something very similar to the old forwarding topology.

SzymonPobiega commented 4 years ago

@rawk01 can you open the ServiceBus Explorer and check how your subscriptions to bundle-1 topic look like?

rawk01 commented 4 years ago

image Image attached - This is sort of what I expect it to look like, I have 3 different types of events I publish from the client end - if I publish any of these events I get 2 copies of them at the ASB end of things.

If it helps I can chop my code down to a minimum and zip it up?

SzymonPobiega commented 4 years ago

If it helps I can chop my code down to a minimum and zip it up?

Sure. Also, can you try take a screenshot using ServiceBus Explorer. Here's how my Router test namespace looks like

image

The new transport subscriptions under bundle-1 topic don't have the $default rule. The old style bridge.events topic do use the $default one. Can you check what is the filtering expression there?

rawk01 commented 4 years ago

Interesting - I don't think I'm using an older one anywhere, but I wonder if there's some old stuff in my prototype: image

rawk01 commented 4 years ago

MixedTransportsMSMQASB.zip

My sample code here - I took the MixedTransport sample and modified from there. I just tried deleting the bundle-1 topic and just restarted the router project, that still created a 'Default' rule, so maybe I have everything wrong!

All connection strings are in Shared->Constants.cs

SzymonPobiega commented 4 years ago

Hi

Sorry for a late reply. I looked at your sample and found these lines

var asbRouterSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(Constants.ASBRouterSubscriptionStorageDB), "RouterASBSubscriptions", new SqlDialect.MsSqlServer(), null);
asbInterface.EnableMessageDrivenPublishSubscribe(asbRouterSubscriptionStorage);

are causing the problem. ASB supports native pub sub via topics. Enabling message driven pub sub causes double even delivery because each event is published both natively and via the message-driven mechanism. I have raised issue to fix it in one of the next releases.

For now just remove this lines and you'll be good. Sorry for the inconveniance.

rawk01 commented 4 years ago

Ahh I see that makes sense. Many thanks for taking the time to look into it, much appreciated!