Skip to content

Instantly share code, notes, and snippets.

@ellieayla
Created March 7, 2020 17:53
Show Gist options
  • Save ellieayla/649dfd2e8f883a8af3653a0f5c3f444a to your computer and use it in GitHub Desktop.
Save ellieayla/649dfd2e8f883a8af3653a0f5c3f444a to your computer and use it in GitHub Desktop.
eventhub-send-deadlock-issue
import logging
import time
import json
from azure.eventhub import EventHubProducerClient, EventData
CONNECTION_STRING='Endpoint=sb://example.servicebus.windows.net/;SharedAccessKeyName=someone;SharedAccessKey=secret'
EVENTHUB_NAME='example'
logger = logging.getLogger(__name__)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
producer_client = EventHubProducerClient.from_connection_string(
conn_str=CONNECTION_STRING,
eventhub_name=EVENTHUB_NAME,
keep_alive=10,
idle_timeout=10,
retry_total=1,
logging_enable=False,
receive_timeout=10,
send_timeout=10,
)
print("Configuration of client:", producer_client._config.__dict__)
producer_client._debug = True
try:
with producer_client:
for i in range(5000):
event_data_batch = producer_client.create_batch()
now = int(time.time())
body = {"timestamp": now, "metric": "debug.eventhub.sender", "value": i}
print("Sending message: {}: {}".format(i, body))
event_data_batch.add(EventData(body=json.dumps(body)))
producer_client.send_batch(event_data_batch)
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
print("Got here!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment