EventHubClient Class

The EventHubClient class defines a high level interface for sending events to and receiving events from the Azure Event Hubs service.

Inheritance
builtins.object
EventHubClient

Constructor

EventHubClient(address, username=None, password=None, debug=False, http_proxy=None, auth_timeout=60, sas_token=None)

Parameters

address
username
default value: None
password
default value: None
debug
default value: False
http_proxy
default value: None
auth_timeout
default value: 60
sas_token
default value: None

Methods

add_epoch_receiver

Add a receiver to the client with an epoch value. Only a single epoch receiver can connect to a partition at any given time - additional epoch receivers must have a higher epoch value or they will be rejected. If a 2nd epoch receiver has connected, the first will be closed.

add_receiver

Add a receiver to the client for a particular consumer group and partition.

add_sender

Add a sender to the client to EventData object to an EventHub.

create_properties

Format the properties with which to instantiate the connection. This acts like a user agent over HTTP.

from_connection_string

Create an EventHubClient from a connection string.

from_iothub_connection_string

Create an EventHubClient from an IoTHub connection string.

from_sas_token

Create an EventHubClient from an existing auth token or token generator.

get_eventhub_info

Get details on the specified EventHub. Keys in the details dictionary include:

-'name' -'type' -'created_at' -'partition_count' -'partition_ids'

run

Run the EventHubClient in blocking mode. Opens the connection and starts running all Sender/Receiver clients. Returns a list of the start up results. For a succcesful client start the result will be None, otherwise the exception raised. If all clients failed to start, then run will fail, shut down the connection and raise an exception. If at least one client starts up successfully the run command will succeed.

stop

Stop the EventHubClient and all its Sender/Receiver clients.

add_epoch_receiver

Add a receiver to the client with an epoch value. Only a single epoch receiver can connect to a partition at any given time - additional epoch receivers must have a higher epoch value or they will be rejected. If a 2nd epoch receiver has connected, the first will be closed.

add_epoch_receiver(consumer_group, partition, epoch, prefetch=300, operation=None, keep_alive=30, auto_reconnect=True)

Parameters

consumer_group
str
Required

The name of the consumer group.

partition
str
Required

The ID of the partition.

epoch
int
Required

The epoch value for the receiver.

prefetch
int
default value: 300

The message prefetch count of the receiver. Default is 300.

operation
default value: None
keep_alive
default value: 30
auto_reconnect
default value: True

Return type

add_receiver

Add a receiver to the client for a particular consumer group and partition.

add_receiver(consumer_group, partition, offset=None, prefetch=300, operation=None, keep_alive=30, auto_reconnect=True)

Parameters

consumer_group
str
Required

The name of the consumer group.

partition
str
Required

The ID of the partition.

offset
Offset
default value: None

The offset from which to start receiving.

prefetch
int
default value: 300

The message prefetch count of the receiver. Default is 300.

operation
default value: None
keep_alive
default value: 30
auto_reconnect
default value: True

Return type

add_sender

Add a sender to the client to EventData object to an EventHub.

add_sender(partition=None, operation=None, send_timeout=60, keep_alive=30, auto_reconnect=True)

Parameters

partition
default value: None

Optionally specify a particular partition to send to. If omitted, the events will be distributed to available partitions via round-robin.

send_timeout
int
default value: None

The timeout in seconds for an individual event to be sent from the time that it is queued. Default value is 60 seconds. If set to 0, there will be no timeout.

keep_alive
int
default value: 60

The time interval in seconds between pinging the connection to keep it alive during periods of inactivity. The default value is 30 seconds. If set to None, the connection will not be pinged.

auto_reconnect
default value: 30

Whether to automatically reconnect the sender if a retryable error occurs. Default value is True.

auto_reconnect
default value: True

Return type

create_properties

Format the properties with which to instantiate the connection. This acts like a user agent over HTTP.

create_properties()

Return type

from_connection_string

Create an EventHubClient from a connection string.

from_connection_string(conn_str, eventhub=None, **kwargs)

Parameters

conn_str
str
Required

The connection string.

eventhub
str
Required

The name of the EventHub, if the EntityName is not included in the connection string.

debug
bool
default value: None

Whether to output network trace logs to the logger. Default is False.

http_proxy
dict[str, <xref:Any>]
Required

HTTP proxy settings. This must be a dictionary with the following keys: 'proxy_hostname' (str value) and 'proxy_port' (int value). Additionally the following keys may also be present: 'username', 'password'.

auth_timeout
int
Required

The time in seconds to wait for a token to be authorized by the service. The default value is 60 seconds. If set to 0, no timeout will be enforced from the client.

from_iothub_connection_string

Create an EventHubClient from an IoTHub connection string.

from_iothub_connection_string(conn_str, **kwargs)

Parameters

conn_str
str
Required

The connection string.

debug
bool
Required

Whether to output network trace logs to the logger. Default is False.

http_proxy
dict[str, <xref:Any>]
Required

HTTP proxy settings. This must be a dictionary with the following keys: 'proxy_hostname' (str value) and 'proxy_port' (int value). Additionally the following keys may also be present: 'username', 'password'.

auth_timeout
int
Required

The time in seconds to wait for a token to be authorized by the service. The default value is 60 seconds. If set to 0, no timeout will be enforced from the client.

from_sas_token

Create an EventHubClient from an existing auth token or token generator.

from_sas_token(address, sas_token, eventhub=None, **kwargs)

Parameters

address
str
Required

The Event Hub address URL

sas_token
str or callable
Required

A SAS token or function that returns a SAS token. If a function is supplied, it will be used to retrieve subsequent tokens in the case of token expiry. The function should take no arguments.

eventhub
str
Required

The name of the EventHub, if not already included in the address URL.

debug
bool
default value: None

Whether to output network trace logs to the logger. Default is False.

http_proxy
dict[str, <xref:Any>]
Required

HTTP proxy settings. This must be a dictionary with the following keys: 'proxy_hostname' (str value) and 'proxy_port' (int value). Additionally the following keys may also be present: 'username', 'password'.

auth_timeout
int
Required

The time in seconds to wait for a token to be authorized by the service. The default value is 60 seconds. If set to 0, no timeout will be enforced from the client.

get_eventhub_info

Get details on the specified EventHub. Keys in the details dictionary include:

-'name' -'type' -'created_at' -'partition_count' -'partition_ids'

get_eventhub_info()

Return type

run

Run the EventHubClient in blocking mode. Opens the connection and starts running all Sender/Receiver clients. Returns a list of the start up results. For a succcesful client start the result will be None, otherwise the exception raised. If all clients failed to start, then run will fail, shut down the connection and raise an exception. If at least one client starts up successfully the run command will succeed.

run()

Return type

stop

Stop the EventHubClient and all its Sender/Receiver clients.

stop()