0

I have two consumers (different applications) connected to an Azure queue. I can either ReceiveAndDelete or PeekLock the messages and during consumption I can complete() or abandon() the message. Ref: http://msdn.microsoft.com/en-us/library/azure/hh851750.aspx.

I'm sure I want to use PeekLock and then abandon() the messages, as I want them to be received in both applications. I figured I'd set the message lifetime on 10 seconds on the queue as a deletion mechanism.

However, as the messages seem to be deleted after 10 seconds, they keep being published in both applications over and over again during those 10 seconds. Should I create some custom duplication detection or am I using a wrong approach in general?

Emily Gerner
  • 2,427
  • 16
  • 16
Ropstah
  • 17,538
  • 24
  • 120
  • 194

1 Answers1

2

In my experience, when you use PeeKLock, you will need to almost always finalize using the Complete Method. The Abandon method is creating the duplicity as it's never marked as "done".

Have you considered using the Service Bus Topics/Subscriptions pattern, or perhaps Filters? If I understand your scenario correctly, it may be just what you need. You can send 2 messages to the queue with different topics or filters designating which app it is for.

http://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-topics-subscriptions/

Please let me know if this helps, or if this does not match your situation.

Kindest regards...

DanielG
  • 1,669
  • 1
  • 12
  • 26
  • This seems to be exactly what I was looking for. Thanks! – Ropstah Oct 31 '14 at 13:06
  • However after implementing the result seems to be the same. I need to have multiple subscriptions for the "AllMessages" filter. At this point a message sent with a certain topic is only received by one of the two applications (seems random). After `complete()` it's gone and the other applications don't receive it anymore. This doesn't make sense according to the document which states: *"Now when a message is sent to "TestTopic", it will always be delivered to receivers subscribed to the "AllMessages" topic subscription, and selectively delivered to receivers subscribed to the ..."* – Ropstah Oct 31 '14 at 15:11
  • Can you potentially send the message twice? In the first one, use a filer like "DestinedForAppA", and the other "DestinedForAppB". Alternatively, send a single message with "DestinedForAppA", then when that message is processed, create another message from that consumer that has "DestinedForAppB". In that model, the message only needs to be sent once, and the consumer of Filter A creates a new queued message for the Fitler B consumer. These are only ideas, so I apologize if my responses make no sense. :-) Only trying to help because I feel your pain. – DanielG Oct 31 '14 at 16:59
  • I've read about this approach and your comment makes sense. However the approach doesn't. `AppA` has absolutely nothing to do with `AppB` and in a similar approach where `AppC` (publisher) sends multiple messages (one for each app), it feels uncomfortable to lay more load on `AppC` to have it send a message for each subscriber of the (ServiceBus) queue. This seems like a job for Azure. What if for instance I have 50 apps subscribed to the queue? Shouldn't it be possible to just add more subscribers which start receiving messages without modifying existing applications? – Ropstah Nov 03 '14 at 21:44
  • The only thing I can think that may help would be to use Azure Queues and updating messages in place, or use the Azure Service Bus with message sessions. The concept is the same; each time a consumer reads the message, it checks a value left by the previous consumer and decides which app receives the information. It updates the message for the next consumer. Finally, if the last app has been updated, it clears the message. You can add more subscribers, but somehow you have to know when the processing is finished and the message can be removed, without duplicating. – DanielG Nov 04 '14 at 15:20
  • Ah so a consumer can edit (or flag) a message and that value is by reference so on `abandon()` it will abandon an edited message for other consumers? – Ropstah Nov 08 '14 at 20:50