dotnetcore / CAP

Distributed transaction solution in micro-service base on eventually consistency, also an eventbus with Outbox pattern
http://cap.dotnetcore.xyz
MIT License
6.68k stars 1.29k forks source link

Azure Service Bus session support #828

Closed jonekdahl closed 3 years ago

jonekdahl commented 3 years ago

Hi,

First of all, thanks for creating CAP, it seems very useful!

We're planning to use CAP to implement the outbox pattern, publishing messages via Azure Service Bus that will be consumed by non-CAP services. We would like to use Service Bus sessions to ensure that multiple messages for the same entity are delivered in FIFO order, but it seems that Service Bus sessions are not supported by CAP.

As far as we could tell, there is no way to pass a session id in a message so that AzureServiceBusTransport will pick it up and propagate it correctly. If this is a misunderstanding, please enlighten us by showing us how to do it.

Our understanding is that, in order to implement sessions, a session id must be added as a special property in the Service Bus message. This is an example where we have extended the message construction in AzureServiceBusTransport with the SessionId property:

                var message = new Microsoft.Azure.ServiceBus.Message
                {
                    MessageId = transportMessage.GetId(),
                    Body = transportMessage.Body,
                    Label = transportMessage.GetName(),
                    CorrelationId = transportMessage.GetCorrelationId(),
                    SessionId = <sessionId> // Get sessionId from somewhere, presumably message headers?
                };

Would you be interested in adding support for sessions? With your guidance, we could prepare a PR for this feature.

yang-xiaodong commented 3 years ago

Hello Jon,

Yes, we are happy to add support for sessions. You are right, this can be read from the message header example such as KafkaHeaders.cs

PR is welcome, thanks

jonekdahl commented 3 years ago

Hi again, there is now an initial PR for adding session support.

jonekdahl commented 3 years ago

Thanks for merging the PR @yang-xiaodong. Would you consider making a preview release?

yang-xiaodong commented 3 years ago

Hi @jonekdahl ,

Version 5.0.2-preview-135224594 has been released to nuget in a few minutes ago, Thanks for your PR!

thisispaulsmith commented 3 years ago

@jonekdahl out of interest what do you use at the consumer side? Handhold or something like Masstransit?

jonekdahl commented 3 years ago

@thisispaulsmith Our consumers use the Service Bus client libraries from Microsoft.