Skip to main content

MCP Python worker extension for Azure Functions.

Project description

Azure Functions Extensions Bindings ServiceBus library for Python

This library allows ServiceBus Triggers in Python Function Apps to recognize and bind to client types from the Azure ServiceBus sdk.

The SDK types can be generated from:

  • ServiceBus Triggers

The supported ServiceBus SDK types include:

  • ServiceBusReceivedMessage

Source code | Package (PyPi) | Samples

Getting started

Prerequisites

Install the package

Install the Azure Functions Extensions Bindings ServiceBus library for Python with pip:

pip install azurefunctions-extensions-bindings-servicebus

Bind to the SDK-type

The Azure Functions Extensions Bindings ServiceBus library for Python allows you to create a function app with a ServiceBus Trigger and define the type as a ServiceBusReceivedMessage. Instead of receiving a ServiceBusMessage, when the function is executed, the type returned will be the defined SDK-type and have all the properties and methods available as seen in the Azure ServiceBus library for Python.

import logging
import azure.functions as func
import azurefunctions.extensions.bindings.servicebus as servicebus

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

@app.service_bus_queue_trigger(arg_name="receivedmessage",
                               queue_name="QUEUE_NAME",
                               connection="SERVICEBUS_CONNECTION")
def servicebus_queue_trigger(receivedmessage: servicebus.ServiceBusReceivedMessage):
    logging.info("Python ServiceBus queue trigger processed message.")
    logging.info("Receiving: %s\n"
                 "Body: %s\n"
                 "Enqueued time: %s\n"
                 "Lock Token: %s\n"
                 "Locked until : %s\n"
                 "Message ID: %s\n"
                 "Sequence number: %s\n",
                 receivedmessage,
                 receivedmessage.body,
                 receivedmessage.enqueued_time_utc,
                 receivedmessage.lock_token,
                 receivedmessage.locked_until,
                 receivedmessage.message_id,
                 receivedmessage.sequence_number)

Troubleshooting

General

The SDK-types raise exceptions defined in Azure Core.

This list can be used for reference to catch thrown exceptions. To get the specific error code of the exception, use the error_code attribute, i.e, exception.error_code.

Next steps

More sample code

Get started with our ServiceBus samples.

Several samples are available in this GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Azure ServiceBus:

  • servicebus_samples_single - Examples for using the ServiceBusReceivedMessage type:

    • From ServiceBus Queue Trigger (Single Message)
    • From ServiceBus Topic Trigger (Single Message)
  • servicebus_samples_batch - Examples for interacting with batches:

    • From ServiceBus Queue Trigger (Batch)
    • From ServiceBus Topic Trigger (Batch)

Additional documentation

For more information on the Azure ServiceBus SDK, see the Azure ServiceBus SDK documentation on docs.microsoft.com and the Azure ServiceBus README.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

victorias_test_package-4.0.0a2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

victorias_test_package-4.0.0a2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file victorias_test_package-4.0.0a2.tar.gz.

File metadata

File hashes

Hashes for victorias_test_package-4.0.0a2.tar.gz
Algorithm Hash digest
SHA256 efd8a00ef697d9784e3cd0914bcf58e096afed777c737b8a94539dda5dfd86d7
MD5 69d547ec193f8b5dac33e32e75bd3354
BLAKE2b-256 457416688091d49c53b41d848c5e1e200c6a46c075d4908b657baf15b9caa8e4

See more details on using hashes here.

File details

Details for the file victorias_test_package-4.0.0a2-py3-none-any.whl.

File metadata

File hashes

Hashes for victorias_test_package-4.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 4cda780d632eb700fc12f9d520c4312122fd92f7075f7b51e3c19f7c1988e164
MD5 ea4712b01bd5bbd1f0e77e8b45424e72
BLAKE2b-256 b2d2bf9efa87c19e4ed8936c9ee4d78d6ac543dcd63d059414c7e0e539996de2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page