Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Provide cancellation token in AcceptMessageSession #293

Closed
ddobric opened this issue Jun 20, 2019 · 4 comments
Closed

[feature] Provide cancellation token in AcceptMessageSession #293

ddobric opened this issue Jun 20, 2019 · 4 comments

Comments

@ddobric
Copy link

ddobric commented Jun 20, 2019

Method AcceptMessageSession should make a usage of cancellation.

AcceptMessageSession (TimeSpan, CancellationToken)

Following code could be in this case simplified:

public async Task Start(CancellationToken cancelToken)
       {
           Task[] tasks = new Task[2];

           tasks[0] = Task.Run(async () =>
           {
               while (!cancelToken.IsCancellationRequested)
               {
                   try
                   {
                       var session = await this.SessionClient.AcceptMessageSessionAsync();
                       Debug.WriteLine($"Session: {session.SessionId}");                      
                   }
                   catch (ServiceBusTimeoutException ex)
                   {
                     
                   }
               }
           }, cancelToken);

           tasks[1] = Task.Run(async ()=> {
               while (!cancelToken.IsCancellationRequested)
               {
                   await Task.Delay(500);
               }
           });

           Task.WaitAny(tasks);
       } 

With cancellation:

public async Task Start(CancellationToken cancelToken)
       {
           Task[] tasks = new Task[2];

           tasks[0] = Task.Run(async () =>
           {
               while (!cancelToken.IsCancellationRequested)
               {
                   try
                   {
                       var session = await this.SessionClient.AcceptMessageSessionAsync(cancelToken);                      
                   }
                   catch (ServiceBusTimeoutException ex)
                   {
                   }
               }
           }, cancelToken);
       }
@SeanFeldman
Copy link
Contributor

It's not just AcceptMessageSession() almost all async operations that involve IO work should have that support. For example: Azure/azure-service-bus-dotnet#439, Azure/azure-service-bus-dotnet#258, and Azure/azure-service-bus-dotnet#675.

This is an issue with the client in general. I've tried to convince here, but it didn't happen. With the client moving to a new repository, I'll raise it there (Azure/azure-sdk-for-net#6653), which you can upvote if you'd like. Either way, it belongs to https://github.com/Azure/azure-sdk-for-net/

@Areson
Copy link

Areson commented Oct 3, 2019

I'd like to add my support to this as well. I have a message queue feeding a constrained resource, and from time to time that resource will issue an alert that it needs to stop processing for a time. I have to close the QueueClient at that point, but the message pumps keep functioning despite the client being closed, which causes a lot of noise.

@Mortana89
Copy link

Same here, we should be able to suspend the message pump without closing the client (sending should still be possible)

@EldertGrootenboer
Copy link
Contributor

If this issue still occurs using the latest SDK, please let us know and we can re-open the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants