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 REQ] Get quick overview of available sessions #7380

Closed
CoenraadS opened this issue Aug 23, 2019 · 9 comments
Closed

[FEATURE REQ] Get quick overview of available sessions #7380

CoenraadS opened this issue Aug 23, 2019 · 9 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved. Service Attention Workflow: This issue is responsible by Azure service team. Service Bus
Milestone

Comments

@CoenraadS
Copy link

CoenraadS commented Aug 23, 2019

Hello

I would like to build a worker/consumer using session queues. However my consumers are ACI containers that I would like to scale out based on the amount of sessions.

To do this I would like an option to either quickly get an overview of all sessions, or all non-locked sessions (without having to accept/lock/iterate all sessions), I just want a list of id's)

Basic scenario
cronjob checks how many unlocked sessions there are and based on this makes N aci consumers
the acis will then request an unlocked session from the service bus

Describe the solution you'd like

Something like

QueueClient.GetMessageSessionsAsync(queueName) // This exists in the WebJobs package, why not in the Microsoft.Azure.ServiceBus; package?
OR
QueueClient.GetUnlockedSessionIds(queueName)

Describe alternatives you've considered

while (true)
sessionClient.AcceptMessageSessionAsync()

This is very ugly/inefficient and inaccurate. I create 10 sessions and this method returns

2 6 8 9 4 1 7 0 Duplicate Duplicate Duplicate Duplicate Duplicate Duplicate Duplicate Duplicate Duplicate Duplicate Duplicate 5 Duplicate Duplicate 3

To remove the duplicates I can hold a lock on every session until I get no more response. This may break a consumer trying to retrieve a work item..

Not a great way of doing things.

@triage-new-issues triage-new-issues bot added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Aug 23, 2019
@kaerm kaerm added Client This issue points to a problem in the data-plane of the library. Service Bus labels Aug 26, 2019
@triage-new-issues triage-new-issues bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Aug 26, 2019
@kaerm kaerm added customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team. labels Aug 26, 2019
@ghost
Copy link

ghost commented Aug 26, 2019

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jfggdl

@axisc axisc self-assigned this Aug 28, 2019
@Petermarcu Petermarcu added the feature-request This issue requires a new behavior in the product in order be resolved. label Aug 30, 2019
@axisc
Copy link

axisc commented Sep 3, 2019

@CoenraadS

Thanks for sharing your feedback.

I wanted to check if you just care about the number of message sessions (that aren't currently locked and hence available to be processed) or do you actually need a list of session ids.

The former could perhaps be surfaced as a metric in Azure Monitor (we don't have it now). You could scale up your receiver applications by driving off this metric.

Let us know what you think.

Also, the code sample you have shared - did you consider using a SessionHandler? It avoids having to poll the queue for sessions.

@CoenraadS
Copy link
Author

CoenraadS commented Sep 3, 2019

For my minimum needs I just need a count. I run a cronjob that then scales ACI or AKS (China doesn't have ACI yet, if it was a metric I would probably have to wait a long time for it to appear in China also?). SessionHandler doesn't really help me for this scenario.

A metric would definitivly be nice though, but I am not consuming this service in a normal way I think.

For my full use case I would definitely also like the id's, because I would like to build my own locking system on top of service bus using redis. (I want the ability to clear a session queue at any time without having to find a worker to break the lock, so I don't use service bus to lock the message).

So actually I want a quick way to get all the ids, so that I can compare them to the id's I'm storing in redis as 'locked'. All the sessions will be unlocked 99% of the time in my case because I never accept them unless I want to peek/complete a message.

@jfggdl jfggdl added this to the Sprint 159 milestone Sep 16, 2019
@axisc
Copy link

axisc commented Sep 27, 2019

@CoenraadS - not sure if the mechanics line up that well. Perhaps I'm not fully grokking your use-case, do you have some pseudocode to share? Specifically - what is meant by 'clearing a session queue'.

Sessions are locked on the service side, even to process a single message. The idea is to simplify your model by taking the responsibility off your plate. Perhaps the worker threads that lock the session can register the lock (insert an entry) on a redis instance if that is something you want to drive your logic on and then unregister the lock (remove the entry) when it gives it up.

@jfggdl
Copy link

jfggdl commented Oct 4, 2019

@CoenraadS, do you have a pseudocode you can share? Are you ok with the approach that Axisc is suggesting ?

@CoenraadS
Copy link
Author

CoenraadS commented Oct 8, 2019

Yes, this is what we implemented on .Net Framework. We 'lock' the session using Redis, however I'm still missing a way to simply iterate sessions simply using .net core.

In Framework I use:

        static readonly MessagingFactory messageFactory = MessagingFactory.CreateFromConnectionString(AppSettings.ServiceBusConnection);

 public static async Task<IEnumerable<MessageSession>> GetSessionsReadonlyAsync(string queue)
        {
            var queueClient = messageFactory.CreateQueueClient(queue);
            return await queueClient.GetMessageSessionsAsync();
        }

But I don't see this functionality in the .net core packages.

@jsquire
Copy link
Member

jsquire commented Feb 26, 2020

Moving to the backlog milestone to sync with the backlog tag for the issue.

@davidallyoung
Copy link

davidallyoung commented Jan 22, 2021

Hi, I wanted to bump this and see if the ASB team has had further consideration around exposing a Sessions metric, or exposing the ability to retrieve this through a client? I think as more workloads move to picking up event driven scalers like KEDA, this is going to become a more prevalent need. For our case specifically, we utilize sessions in some scenarios for tenancy prioritization and workload distribution. Our current scale-out is really clunky, but if we could tap how many sessions were currently on the queue we could greatly simplify it and increase it's reliability. This could be via a metric or exposed on a client as the OP indicated.

@ramya-rao-a
Copy link
Contributor

Hello all,

Thanks for your patience

Please note that a newer package Azure.Messaging.ServiceBus is available as of November 2020. While the older Microsoft.Azure.ServiceBus package for which this issue was logged will continue to receive critical bug fixes, we strongly encourage you to upgrade. Read the migration guide for more details.

#20569 is the issue tracking this same feature request for the new package

@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved. Service Attention Workflow: This issue is responsible by Azure service team. Service Bus
Projects
None yet
Development

No branches or pull requests

9 participants