Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.64k stars 2.84k forks source link

Get service bus sender client by name regardless of type (queue/topic) #36192

Closed ietz closed 2 days ago

ietz commented 5 months ago

Is your feature request related to a problem? Please describe. I would like a way to send messages to an Azure Service Bus entity without needing to know in advance if the entity is a topic or a queue. Currently, the only way to send a message is by first creating a ServiceBusClient and using its .get_queue_sender or .get_topic_sender method to get a ServiceBusSender instance and then using its .send_messages method.

Having to know the type in advance limits the usefulness of the message ReplyTo property for a request-response pattern where some of the responses need to be delivered to a queue while others need to be delivered to a topic.

Describe the solution you'd like Merge the .get_queue_sender and .get_topic_sender methods into a .get_sender method that takes a shared queue_or_topic_name: string parameter, instead of having separate methods or parameters queue_name: string and topic_name: string. As far as I can tell from the docs, this is exactly what the Service Bus .NET SDK does with the ServiceBusClient.CreateSender(string queueOrTopicName) method.

Describe alternatives you've considered Two potential solutions that would work with the current SDK:

Both should work but seem like workarounds and should not be necessary given that the .NET API does not have these limitations

github-actions[bot] commented 5 months ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

kashifkhan commented 1 month ago

@ietz apologies for the delay on this one. The reason for the split is not entirely clear and perhaps lost to time ( with team changes etc etc )

With that said I was looking at our code to see if a nicer workaround would be available in your case and there is - with the way urls and the service structures entities you can pass in a queue name or a topic name into the sender ( either topic sender or queue sender ) and it will work.

I tested this with a sample - typed in my topic name in to get_queue_sender and the messages landed in the topic and showed up in my subscription. Tried it the other way and the messages showed up in my queue.

We will look in to potentially adding an overload in the future but given how long these APIs have been around might need some further thinking.

In the mean time hopefully this workaround works.

github-actions[bot] commented 1 week ago

Hi @ietz. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] commented 2 days ago

Hi @ietz, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.