airflow.providers.microsoft.azure.hooks.asb

Module Contents

Classes

BaseAzureServiceBusHook

BaseAzureServiceBusHook class to create session and create connection using connection string.

AdminClientHook

Interact with the ServiceBusAdministrationClient.

MessageHook

Interact with ServiceBusClient.

class airflow.providers.microsoft.azure.hooks.asb.BaseAzureServiceBusHook(azure_service_bus_conn_id=default_conn_name)[source]

Bases: airflow.hooks.base.BaseHook

BaseAzureServiceBusHook class to create session and create connection using connection string.

Parameters

azure_service_bus_conn_id (str) – Reference to the Azure Service Bus connection.

conn_name_attr = 'azure_service_bus_conn_id'[source]
default_conn_name = 'azure_service_bus_default'[source]
conn_type = 'azure_service_bus'[source]
hook_name = 'Azure Service Bus'[source]
classmethod get_connection_form_widgets()[source]

Return connection widgets to add to connection form.

classmethod get_ui_field_behaviour()[source]

Return custom field behaviour.

abstract get_conn()[source]

Return connection for the hook.

class airflow.providers.microsoft.azure.hooks.asb.AdminClientHook(azure_service_bus_conn_id=default_conn_name)[source]

Bases: BaseAzureServiceBusHook

Interact with the ServiceBusAdministrationClient.

This can create, update, list, and delete resources of a Service Bus namespace. This hook uses the same Azure Service Bus client connection inherited from the base class.

get_conn()[source]

Create a ServiceBusAdministrationClient instance.

This uses the connection string in connection details.

create_queue(queue_name, max_delivery_count=10, dead_lettering_on_message_expiration=True, enable_batched_operations=True)[source]

Create Queue by connecting to service Bus Admin client return the QueueProperties.

Parameters
  • queue_name (str) – The name of the queue or a QueueProperties with name.

  • max_delivery_count (int) – The maximum delivery count. A message is automatically dead lettered after this number of deliveries. Default value is 10..

  • dead_lettering_on_message_expiration (bool) – A value that indicates whether this subscription has dead letter support when a message expires.

  • enable_batched_operations (bool) – Value that indicates whether server-side batched operations are enabled.

delete_queue(queue_name)[source]

Delete the queue by queue_name in service bus namespace.

Parameters

queue_name (str) – The name of the queue or a QueueProperties with name.

delete_subscription(subscription_name, topic_name)[source]

Delete a topic subscription entities under a ServiceBus Namespace.

Parameters
  • subscription_name (str) – The subscription name that will own the rule in topic

  • topic_name (str) – The topic that will own the subscription rule.

class airflow.providers.microsoft.azure.hooks.asb.MessageHook(azure_service_bus_conn_id=default_conn_name)[source]

Bases: BaseAzureServiceBusHook

Interact with ServiceBusClient.

This acts as a high level interface for getting ServiceBusSender and ServiceBusReceiver.

get_conn()[source]

Create and returns ServiceBusClient by using the connection string in connection details.

send_message(queue_name, messages, batch_message_flag=False)[source]

Use ServiceBusClient Send to send message(s) to a Service Bus Queue.

By using batch_message_flag, it enables and send message as batch message.

Parameters
  • queue_name (str) – The name of the queue or a QueueProperties with name.

  • messages (str | list[str]) – Message which needs to be sent to the queue. It can be string or list of string.

  • batch_message_flag (bool) – bool flag, can be set to True if message needs to be sent as batch message.

static send_list_messages(sender, messages)[source]
static send_batch_message(sender, messages)[source]
receive_message(queue_name, max_message_count=1, max_wait_time=None)[source]

Receive a batch of messages at once in a specified Queue name.

Parameters
  • queue_name – The name of the queue name or a QueueProperties with name.

  • max_message_count (int | None) – Maximum number of messages in the batch.

  • max_wait_time (float | None) – Maximum time to wait in seconds for the first message to arrive.

receive_subscription_message(topic_name, subscription_name, max_message_count, max_wait_time)[source]

Receive a batch of subscription message at once.

This approach is optimal if you wish to process multiple messages simultaneously, or perform an ad-hoc receive as a single call.

Parameters
  • subscription_name (str) – The subscription name that will own the rule in topic

  • topic_name (str) – The topic that will own the subscription rule.

  • max_message_count (int | None) – Maximum number of messages in the batch. Actual number returned will depend on prefetch_count and incoming stream rate. Setting to None will fully depend on the prefetch config. The default value is 1.

  • max_wait_time (float | None) – Maximum time to wait in seconds for the first message to arrive. If no messages arrive, and no timeout is specified, this call will not return until the connection is closed. If specified, an no messages arrive within the timeout period, an empty list will be returned.

Was this entry helpful?