examples of output binding to service bus queue
alexgman opened this issue · comments
Is there a way to read/write from service bus queue using python? I know there might not be a way to using an explicit binding, but perhaps there's a manual way where we establish a connection and manually put a message on a service bus queue? My main interest is in triggering with servicebus and then output to servicebus
Just func new
and pick the Service Bus template. Do you mean there's no output binding for Service Bus in the runtime?
DEPRECATED, SEE MY NEXT COMMENT
Use a Storage Queue output binding for your main function and create a second function that triggers on that Storage Queue and writes to Service Bus using the storage SDK. This way, once there's a Service Bus output binding you only need to change configuration, not code. Of course you can do it all in one function if you wish, just a personal preference to separate concerns.
from azure.servicebus import QueueClient, Message
# Create the QueueClient
queue_client = QueueClient.from_connection_string(
"<CONNECTION STRING>", "<QUEUE NAME>")
# Send a test message to the queue
msg = Message(b'Test Message')
queue_client.send(msg)
Don't forget to add azure.servicebus
to your function app's requirements.txt
.
Wait, judging by this there is an output binding for Service Bus. Try that first.
This PR (#26) adds a sample for Service Bus trigger and output. I've tested it, the message gets added to the output Service Bus queue successfully.