Last active
October 20, 2018 08:46
-
-
Save samuelalvin/7401f6461a4efdeb013deedddb95410d to your computer and use it in GitHub Desktop.
.NET Core Azure Service Bus - Part of receiver code for Session Enabled Subscription
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //// This is part of the code for my medium post, https://medium.com/@samuelhutama | |
| static void RegisterOnMessageHandlerAndReceiveMessages() | |
| { | |
| var sessionHandlerOptions = new SessionHandlerOptions(ExceptionReceivedHandlerAsync) | |
| { | |
| //// Maximum number of concurrent calls to the callback ProcessMessagesAsync(), set to 1 for simplicity. | |
| //// Set it according to how many messages the application wants to process in parallel. | |
| MaxConcurrentSessions = 100, | |
| //// Indicates whether MessagePump should automatically complete the messages after returning from User Callback. | |
| //// False below indicates the Complete will be handled by the User Callback as in `ProcessMessagesAsync` below. | |
| AutoComplete = true, | |
| }; | |
| subscriptionClient.RegisterSessionHandler(ProcessMessagesInSessionAsync, sessionHandlerOptions); | |
| } | |
| private static async Task ProcessMessagesInSessionAsync(IMessageSession messageSession, Message message, CancellationToken token) | |
| { | |
| Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}"); | |
| await Task.CompletedTask; | |
| //// We don't use the CompleteAsync() method. | |
| //// await subscriptionClient.CompleteAsync(message.SystemProperties.LockToken); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment