-
Notifications
You must be signed in to change notification settings - Fork 36
Conversation
… for all scenarios
src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Listeners/ServiceBusListener.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/WebJobs.Extensions.ServiceBus.csproj
Show resolved
Hide resolved
src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/WebJobs.Extensions.ServiceBus.csproj
Outdated
Show resolved
Hide resolved
src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/WebJobs.Extensions.ServiceBus.csproj
Outdated
Show resolved
Hide resolved
src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Listeners/ServiceBusListener.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.Azure.WebJobs.Extensions.ServiceBus.Tests/ServiceBusEndToEndTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.Azure.WebJobs.Extensions.ServiceBus.Tests/ServiceBusSessionsEndToEndTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit comment. Looks good otherwise.
if (_clientEntity != null) | ||
{ | ||
if (_clientEntity is QueueClient queueClient) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: last 2 if statements can be merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean lines 140 and 142? If so, I don't want lines 148 and 149 executed on a null _clientEntity so can't check in a single if statement. Would definitely like to compact this if chain!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. You probably can make it easier to read by checking for negation instead. Something like and so on.
if (!_singleDispatch)
{
return:
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have to set the _started flag to false in all cases. Would have to duplicate that logic in two places with the short circuit of (!_singleDispatch) so not sure if that's a better option as more common steps may be added at a later time and those would have to be duplicated.
test/Microsoft.Azure.WebJobs.Extensions.ServiceBus.Tests/README.md
Outdated
Show resolved
Hide resolved
…ompletes messages in the function to improve validation logic.
Azure functions will support draining in-flight messages before shutdown of the runtime. The current extension implementation closes the connection to Service Bus during shutdown before allowing executing function invocations to complete processing and prevents these messages from being completed or abandoned. Additionally, new messages start processing up until the connection to Service Bus is closed.
This PR implements graceful shutdown in the extension by leveraging a new set of "Unregister" methods in the Service Bus SDK : Azure/azure-sdk-for-net#14021 and published in 4.2.0 and 5.0.0 of the Service Bus SDK used by this library.
This extension supports single message as well as batch processing and the message draining implementation is different for each path.
Batch processing:
The ServiceBusListener when created in batch mode, polls Service Bus for messages in a loop while checking to ensure that it is still in started state and no cancellation has been requested. The new Functions runtime "/drain" API will be invoked when the runtime needs to shutdown and sufficient time will be given for any functions that have already been invoked to complete. The invocation of "/drain" calls StopAsync() on all listeners and with this change, the connections to Service Bus will remain open until the runtime is shutdown and Dispose() is called.
Single message processing:
The new QueueClient.UnregisterSessionHandlerAsync, SubscriptionClient.UnregisterSessionHandlerAsync and MessageReceiver.UnregisterMessageHandlerAsync methods are called when the extension is stopped. These calls block until all in-flight messages complete processing (drain) and new messages no longer get dispatched. As the amount of time given to functions to execute depends on the SKU, a MaxValue timespan is specified when draining as the host will shut down regardless after the max function execution time.
Other changes: