-
Notifications
You must be signed in to change notification settings - Fork 107
Converge azure.functions.ServiceBusMessage with azure.servicebus.ServiceBusMessage #1172
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
Comments
@metamoof thanks for reporting the issue, can you try build the azure.servicebus.ServiceBusMessage from azure.functions.ServiceBusMessage which contains all attributes of azure.servicebus.ServiceBusMessage ( ref of azure.functions.ServiceBusMessage: https://github.com/Azure/azure-functions-python-library/blob/bd11d48b19dd226876ae96f7ca26a91ffa8beff6/azure/functions/servicebus.py#L8 ). Servicebus and functions package does not have dependency on each other and it is not a good idea for us to do so. |
I can understand why you do not wish to depend on the servicebus package, but it would be nice if you both had at the very least the same Abstract Base Classes. That being said, and being pragmatic, here's a quick survey of what is in both classes (not including the deprecated or not implemented properties):
So, at first glance, to get API compatible, it seems all I need to do is alias The more difficult part is to make it so that the servicebus SDK will accept a Functions So the solution that comes to me is to take advantage of the fact that Finally, whilst I am going to create some self-contained unit tests for this, I'd appreciate guidance on how to include integration tests that will run against the servicebus SDK. I'd like to ensure that the libraries remain compatible over time. |
@metamoof pls share the all repro steps. |
In a function with a servicebus trigger that has a servicebus configured in the import azure.functions as func
import azure.servicebus
import os
def main(msg: func.ServiceBusMessage):
with azure.servicebus.ServiceBusClient.from_connection_string(
os.environ["SERVICEBUS"]
) as sb:
sender = sb.get_queue_sender("next-step")
sender.send_messages(msg) # Exception: TypeError: Only AmqpAnnotatedMessage, ServiceBusMessage instances or Mappings representing messages are supported. Received instead: ServiceBusMessage |
thanks will check update asap |
@gavin-aguiar pls comment and validate |
Currently this is not supported in python functions. We are working on a feature where the sdk client will be passed as a binding which should help in this case. But the feature is still in progress and will be coming out within a few months. |
@gavin-aguiar @bhagyshricompany, any updates for either metamoof's proposal or the SDK client binding Gavin mentioned? As far as I can tell there is still no solution provided - not sure why it was marked completed. |
@gavin-aguiar I think this is the feature you were referring to? It seems it still does not support the Service Bus SDK. Even if it did, that would not solve this issue as the provided SDK client still wouldn't accept an |
This is copied over from Azure/azure-sdk-for-python#26827 as it was suggested I should post it in here.
I deal with a lot of code in azure functions that requires me to process messages in a ServiceBus queue, and then pass that message on untouched. However, despite the fact that an Azure Functions ServiceBus Queue Trigger passes in an
azure.functions.ServiceBusMessage
,azure.servicebus.ServiceBusSender
does not accept that kind of message, preferring to throw the rather cryptic error:Exception: TypeError: Only AmqpAnnotatedMessage, ServiceBusMessage instances or Mappings representing messages are supported. Received instead: ServiceBusMessage
.And as such, my code is peppered with this boilerplate:
Also, knowing when to use
application_properties
oruser_properties
drives me a little crazy, and means I can't just do something likemessage = azure.servicebus.ServiceBusMessage(**msg.__dict__)
or somesuch.Describe the solution you'd like
Ideally, some sort of convergence, in which
azure.functions.ServiceBusMessage
is a subclass ofazure.servicebus.ServiceBusMessage
, but implementing the old API as backwards-compatible aliases, and eventually deprecating the APIs that are not inazure.servicebus.ServiceBusMessage
. I can see no reason why they need to be separate classes.Describe alternatives you've considered
Somewhat messier alternatives:
azure.servicebus.ServiceBusSender.send_messages()
to acceptazure.functions.ServiceBusMessage
instancesazure.servicebus.ServiceBusMessage.from_azure_functions_message()
constructor that creates one from the otherThe text was updated successfully, but these errors were encountered: