I am receiving data through azure eventhub and trying to close if I am receiving no more data for like 10 or 15 seconds.
I tried to implement arguments auth_timeout
and idel_timeout
in _consumer_client, but neither worked.
I am also referring to this example.
There's "on_error" function that may function to close the client when there's no further message being consumed.
def on_event(partition_context, event):
## My Code##
# Put your code here. to do some operations on the event.
print("Received event from partition {}.".format(partition_context.partition_id))
print("Last enqueued event properties from partition: {} is: {}.".format(
partition_context.partition_id,t))
def on_error(partition_context, error):
# Put your code here. partition_context can be None in the on_error callback.
if partition_context:
print("An exception: {} occurred during receiving from Partition: {}.".format(
partition_context.partition_id,
error
))
else:
print("An exception: {} occurred during the load balance process.".format(error))
consumer_client = EventHubConsumerClient.from_connection_string(conn_str=CONNECTION_STR,consumer_group='forceconsummer',eventhub_name=EVENTHUB_NAME, idle_timeout = 30, auth_timeout = 10)
consumer_client.receive(on_event=on_event, partition_id = "2", track_last_enqueued_event_properties=False, on_error=on_error, starting_position="@latest")
How can I make it work to be closed automatically after a timeout?