Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ def _handle_exception(self, exception):

return _handle_exception(exception, self)

def _do_retryable_operation(self, operation, timeout=None, **kwargs):
def _do_retryable_operation(self, operation, timeout=100000, **kwargs):
# pylint:disable=protected-access
if not timeout:
timeout = 100000 # timeout equals to 0 means no timeout, set the value to be a large number.
timeout_time = time.time() + timeout
timeout_time = time.time() + (
timeout if timeout else 100000) # timeout equals to 0 means no timeout, set the value to be a large number.
retried_times = 0
last_exception = kwargs.pop('last_exception', None)
operation_need_param = kwargs.pop('operation_need_param', True)
Expand All @@ -100,7 +99,7 @@ def _do_retryable_operation(self, operation, timeout=None, **kwargs):
timeout_time=timeout_time, entity_name=self._name)
retried_times += 1

log.info("%r has exhausted retry. Exception still occurs (%r)", self._name, last_exception)
log.info("%r operation has exhausted retry. Last exception: %r.", self._name, last_exception)
raise last_exception

def close(self, exception=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ async def _handle_exception(self, exception):

return await _handle_exception(exception, self)

async def _do_retryable_operation(self, operation, timeout=None, **kwargs):
async def _do_retryable_operation(self, operation, timeout=100000, **kwargs):
# pylint:disable=protected-access
if not timeout:
timeout = 100000 # timeout equals to 0 means no timeout, set the value to be a large number.
timeout_time = time.time() + timeout
timeout_time = time.time() + (
timeout if timeout else 100000) # timeout equals to 0 means no timeout, set the value to be a large number.
retried_times = 0
last_exception = kwargs.pop('last_exception', None)
operation_need_param = kwargs.pop('operation_need_param', True)
Expand All @@ -101,7 +100,7 @@ async def _do_retryable_operation(self, operation, timeout=None, **kwargs):
timeout_time=timeout_time, entity_name=self._name)
retried_times += 1

log.info("%r has exhausted retry. Exception still occurs (%r)", self._name, last_exception)
log.info("%r operation has exhausted retry. Last exception: %r.", self._name, last_exception)
raise last_exception

async def close(self, exception=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# --------------------------------------------------------------------------------------------

"""
An example to show sending events asynchronously to an Event Hub with partition keys.
An example to show sending individual events asynchronously to an Event Hub.
"""

# pylint: disable=C0111
Expand Down Expand Up @@ -45,6 +45,4 @@ async def send(producer, count):
run(client))
start_time = time.time()
loop.run_until_complete(tasks)
end_time = time.time()
run_time = end_time - start_time
print("Runtime: {} seconds".format(run_time))
print("Runtime: {} seconds".format(time.time() - start_time))
4 changes: 1 addition & 3 deletions sdk/eventhub/azure-eventhubs/examples/iothub_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
client = EventHubClient.from_connection_string(iot_connection_str, network_tracing=False)
consumer = client.create_consumer(consumer_group="$default", partition_id="0", event_position=EventPosition("-1"),
operation='/messages/events')

with consumer:
received = consumer.receive(timeout=5)
print(received)

eh_info = client.get_properties()
print(eh_info)
5 changes: 1 addition & 4 deletions sdk/eventhub/azure-eventhubs/examples/recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,4 @@
print(event_data.body_as_str())
total += 1
batch = consumer.receive(timeout=5)

end_time = time.time()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
print("Received {} messages in {} seconds".format(total, time.time() - start_time))
11 changes: 6 additions & 5 deletions sdk/eventhub/azure-eventhubs/examples/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# --------------------------------------------------------------------------------------------

"""
An example to show sending events to an Event Hub partition.
This is just an example of sending EventData, not performance optimal.
To have the best performance, send a batch EventData with one send() call.
An example to show sending individual events to an Event Hub partition.
Although this works, sending events in batches will get better performance.
See 'send_list_of_event_data.py' and 'send_event_data_batch.py' for an example of batching.
"""

# pylint: disable=C0111
Expand All @@ -26,10 +26,11 @@
client = EventHubClient(host=HOSTNAME, event_hub_path=EVENT_HUB, credential=EventHubSharedKeyCredential(USER, KEY),
network_tracing=False)
producer = client.create_producer(partition_id="0")

start_time = time.time()
with producer:
# not performance optimal, but works. Please do send events in batch to get much better performance.
for i in range(100):
ed = EventData("msg")
print("Sending message: {}".format(i))
producer.send(ed) # please use batch_send for better performance. Refer to event_data_batch.py
producer.send(ed)
print("Send 100 messages in {} seconds".format(time.time() - start_time))
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@ def create_batch_data(producer):
with producer:
event_data_batch = create_batch_data(producer)
producer.send(event_data_batch)
end_time = time.time()
run_time = end_time - start_time
print("Runtime: {} seconds".format(run_time))
print("Runtime: {} seconds".format(time.time() - start_time))
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
event_list = []
for i in range(1500):
event_list.append(EventData('Hello World'))
start_time = time.time()
with producer:
start_time = time.time()
producer.send(event_list)
print("Runtime: {} seconds".format(time.time() - start_time))