/
azure.eventhub.aio.EventHubProducerClient.yml
896 lines (753 loc) · 37.4 KB
/
azure.eventhub.aio.EventHubProducerClient.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
### YamlMime:PythonClass
uid: azure.eventhub.aio.EventHubProducerClient
name: EventHubProducerClient
fullName: azure.eventhub.aio.EventHubProducerClient
module: azure.eventhub.aio
inheritances:
- azure.eventhub.aio._client_base_async.ClientBaseAsync
summary: 'The EventHubProducerClient class defines a high level interface for
sending events to the Azure Event Hubs service.'
constructor:
syntax: 'EventHubProducerClient(fully_qualified_namespace: str, eventhub_name: str,
credential: CredentialTypes, *, buffered_mode: bool = False, on_error: Callable[[List[EventData
| AmqpAnnotatedMessage], str | None, Exception], Awaitable[None]] | None = None,
on_success: Callable[[List[EventData | AmqpAnnotatedMessage], str | None], Awaitable[None]]
| None = None, max_buffer_length: int | None = None, max_wait_time: float | None
= None, **kwargs: Any)'
parameters:
- name: fully_qualified_namespace
description: 'The fully qualified host name for the Event Hubs namespace.
This is likely to be similar to <yournamespace>.servicebus.windows.net'
isRequired: true
types:
- <xref:str>
- name: eventhub_name
description: The path of the specific Event Hub to connect the client to.
isRequired: true
types:
- <xref:str>
- name: credential
description: 'The credential object used for authentication which
implements a particular interface for getting tokens. It accepts
<xref:azure.eventhub.aio.EventHubSharedKeyCredential>, or credential objects
generated by the azure-identity library and objects that implement the *get_token(self,
*scopes)* method.'
isRequired: true
types:
- <xref:azure.core.credentials_async.AsyncTokenCredential>
- <xref:azure.core.credentials.AzureSasCredential>
- <xref:azure.core.credentials.AzureNamedKeyCredential>
keywordOnlyParameters:
- name: buffered_mode
description: 'If True, the producer client will collect events in a buffer, efficiently
batch,
then publish. Default is False.'
types:
- <xref:bool>
- name: on_success
description: 'The callback to be called once a batch has been successfully published.
The callback takes two parameters:
- *events*: The list of events that have been successfully published
- *partition_id*: The partition id that the events in the list have been published
to.
The callback function should be defined like: *on_success(events, partition_id)*.
Required when *buffered_mode* is True while optional if *buffered_mode* is False.'
types:
- <xref:typing.Optional>[<xref:typing.Callable>[[<xref:SendEventTypes>, <xref:typing.Optional>[<xref:str>]],
<xref:typing.Awaitable>[<xref:None>]]]
- name: on_error
description: 'The callback to be called once a batch has failed to be published.
Required when in *buffered_mode* is True while optional if *buffered_mode* is
False.
The callback function should be defined like: *on_error(events, partition_id,
error)*, where:
- *events*: The list of events that failed to be published,
- *partition_id*: The partition id that the events in the list have been tried
to be published to and
- *error*: The exception related to the sending failure.
If *buffered_mode* is False, *on_error* callback is optional and errors will
be handled as follows:
- If an *on_error* callback is passed during the producer client instantiation,
then error information will be passed to the *on_error* callback, which will
then be called.
- If an *on_error* callback is not passed in during client instantiation,
then the error will be raised by default.
If *buffered_mode* is True, *on_error* callback is required and errors will
be handled as follows:
- If events fail to enqueue within the given timeout, then an error will be
directly raised.
- If events fail to send after enqueuing successfully, the *on_error* callback
will be called.'
types:
- <xref:typing.Optional>[<xref:typing.Callable>[[<xref:SendEventTypes>, <xref:typing.Optional>[<xref:str>],
<xref:Exception>], <xref:typing.Awaitable>[<xref:None>]]]
- name: max_buffer_length
description: 'Buffered mode only.
The total number of events per partition that can be buffered before a flush
will be triggered.
The default value is 1500 in buffered mode.'
types:
- <xref:int>
- name: max_wait_time
description: 'Buffered mode only.
The amount of time to wait for a batch to be built with events in the buffer
before publishing.
The default value is 1 in buffered mode.'
types:
- <xref:typing.Optional>[<xref:float>]
- name: logging_enable
description: Whether to output network trace logs to the logger. Default is *False*.
types:
- <xref:bool>
- name: auth_timeout
description: '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.'
types:
- <xref:float>
- name: user_agent
description: If specified, this will be added in front of the user agent string.
types:
- <xref:str>
- name: retry_total
description: 'The total number of attempts to redo a failed operation when an
error occurs. Default
value is 3.'
types:
- <xref:int>
- name: retry_backoff_factor
description: 'A backoff factor to apply between attempts after the second try
(most errors are resolved immediately by a second try without a delay).
In fixed mode, retry policy will always sleep for {backoff factor}.
In ''exponential'' mode, retry policy will sleep for: *{backoff factor} * (2
** ({number of total retries} - 1))*
seconds. If the backoff_factor is 0.1, then the retry will sleep
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.'
types:
- <xref:float>
- name: retry_backoff_max
description: The maximum back off time. Default value is 120 seconds (2 minutes).
types:
- <xref:float>
- name: retry_mode
description: 'The delay behavior between retry attempts. Supported values are
''fixed'' or ''exponential'',
where default is ''exponential''.'
types:
- <xref:str>
- name: idle_timeout
description: 'Timeout, in seconds, after which this client will close the underlying
connection
if there is no activity. By default the value is None, meaning that the client
will not shutdown due to inactivity
unless initiated by the service.'
types:
- <xref:float>
- name: transport_type
description: 'The type of transport protocol that will be used for communicating
with
the Event Hubs service. Default is *TransportType.Amqp* in which case port 5671
is used.
If the port 5671 is unavailable/blocked in the network environment, *TransportType.AmqpOverWebsocket*
could
be used instead which uses port 443 for communication.'
types:
- <xref:azure.eventhub.TransportType>
- name: http_proxy
description: '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''*.'
types:
- <xref:dict>
- name: custom_endpoint_address
description: 'The custom endpoint address to use for establishing a connection
to
the Event Hubs service, allowing network requests to be routed through any application
gateways or
other paths needed for the host environment. Default is None.
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
If port is not specified in the *custom_endpoint_address*, by default port 443
will be used.'
types:
- <xref:typing.Optional>[<xref:str>]
- name: connection_verify
description: 'Path to the custom CA_BUNDLE file of the SSL certificate which is
used to
authenticate the identity of the connection endpoint.
Default is None in which case *certifi.where()* will be used.'
types:
- <xref:typing.Optional>[<xref:str>]
- name: uamqp_transport
description: 'Whether to use the *uamqp* library as the underlying transport.
The default value is
False and the Pure Python AMQP library will be used as the underlying transport.'
types:
- <xref:bool>
- name: socket_timeout
description: 'The time in seconds that the underlying socket on the connection
should
wait when sending and receiving data before timing out. The default value is
0.2 for TransportType.Amqp
and 1 for TransportType.AmqpOverWebsocket. If EventHubsConnectionError errors
are occurring due to write
timing out, a larger than default value may need to be passed in. This is for
advanced usage scenarios
and ordinarily the default value should be sufficient.'
types:
- <xref:float>
examples:
- "Create a new instance of the EventHubProducerClient.<!--[!code-python[Main](les\\\
async_samples\\sample_code_eventhub_async.py )]-->\n\n<!-- literal_block {\"ids\"\
: [], \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\": [], \"source\"\
: \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.9\\\\x64\\\\Lib\\\\site-packages\\\
\\py2docfx\\\\dist_temp\\\\43\\\\azure-eventhub-5.11.7\\\\samples\\\\async_samples\\\
\\sample_code_eventhub_async.py\", \"xml:space\": \"preserve\", \"force\": false,\
\ \"language\": \"python\", \"highlight_args\": {\"linenostart\": 1}, \"linenos\"\
: false} -->\n\n````python\n\n import os\n from azure.eventhub.aio import EventHubProducerClient,\
\ EventHubSharedKeyCredential\n\n fully_qualified_namespace = os.environ['EVENT_HUB_HOSTNAME']\n\
\ eventhub_name = os.environ['EVENT_HUB_NAME']\n shared_access_policy = os.environ['EVENT_HUB_SAS_POLICY']\n\
\ shared_access_key = os.environ['EVENT_HUB_SAS_KEY']\n\n producer = EventHubProducerClient(fully_qualified_namespace=fully_qualified_namespace,\n\
\ eventhub_name=eventhub_name,\n \
\ credential=EventHubSharedKeyCredential(shared_access_policy,\
\ shared_access_key))\n\n ````\n"
methods:
- uid: azure.eventhub.aio.EventHubProducerClient.close
name: close
summary: Close the Producer client underlying AMQP connection and links.
signature: 'async close(*, flush: bool = True, **kwargs: Any) -> None'
keywordOnlyParameters:
- name: flush
description: 'Buffered mode only. If set to True, events in the buffer will be
sent
immediately. Default is True.'
defaultValue: 'True'
types:
- <xref:bool>
- name: timeout
description: 'Buffered mode only. Timeout to close the producer.
Default is None which means no timeout.'
types:
- <xref:float>
- <xref:None>
return:
types:
- <xref:None>
exceptions:
- type: azure.eventhub.exceptions.EventHubError
description: 'If an error occurred when flushing the buffer if *flush* is set
to True or closing the
underlying AMQP connections in buffered mode.'
examples:
- "Close down the handler.<!--[!code-python[Main](les\\async_samples\\sample_code_eventhub_async.py\
\ )]-->\n\n<!-- literal_block {\"ids\": [], \"classes\": [], \"names\": [], \"\
dupnames\": [], \"backrefs\": [], \"source\": \"C:\\\\hostedtoolcache\\\\windows\\\
\\Python\\\\3.11.9\\\\x64\\\\Lib\\\\site-packages\\\\py2docfx\\\\dist_temp\\\\\
43\\\\azure-eventhub-5.11.7\\\\samples\\\\async_samples\\\\sample_code_eventhub_async.py\"\
, \"xml:space\": \"preserve\", \"force\": false, \"language\": \"python\", \"\
highlight_args\": {\"linenostart\": 1}, \"linenos\": false} -->\n\n````python\n\
\n import os\n from azure.eventhub.aio import EventHubProducerClient\n from\
\ azure.eventhub import EventData\n\n event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR']\n\
\ eventhub_name = os.environ['EVENT_HUB_NAME']\n\n producer = EventHubProducerClient.from_connection_string(\n\
\ conn_str=event_hub_connection_str,\n eventhub_name=eventhub_name\
\ # EventHub name should be specified if it doesn't show up in connection string.\n\
\ )\n try:\n event_data_batch = await producer.create_batch()\n \
\ while True:\n try:\n event_data_batch.add(EventData('Message\
\ inside EventBatchData'))\n except ValueError:\n # The\
\ EventDataBatch object reaches its max_size.\n # You can send the\
\ full EventDataBatch object and create a new one here.\n break\n\
\ await producer.send_batch(event_data_batch)\n finally:\n # Close\
\ down the producer handler.\n await producer.close()\n\n ````\n"
- uid: azure.eventhub.aio.EventHubProducerClient.create_batch
name: create_batch
summary: 'Create an EventDataBatch object with the max size of all content being
constrained by max_size_in_bytes.
The max_size_in_bytes should be no greater than the max allowed message size defined
by the service.'
signature: 'async create_batch(*, partition_id: str | None = None, partition_key:
str | None = None, max_size_in_bytes: int | None = None) -> EventDataBatch'
keywordOnlyParameters:
- name: partition_id
isRequired: true
- name: partition_key
isRequired: true
- name: max_size_in_bytes
isRequired: true
return:
types:
- <xref:azure.eventhub.EventDataBatch>
examples:
- "Create EventDataBatch object within limited size<!--[!code-python[Main](les\\\
async_samples\\sample_code_eventhub_async.py )]-->\n\n<!-- literal_block {\"ids\"\
: [], \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\": [], \"source\"\
: \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.9\\\\x64\\\\Lib\\\\site-packages\\\
\\py2docfx\\\\dist_temp\\\\43\\\\azure-eventhub-5.11.7\\\\samples\\\\async_samples\\\
\\sample_code_eventhub_async.py\", \"xml:space\": \"preserve\", \"force\": false,\
\ \"language\": \"python\", \"highlight_args\": {\"linenostart\": 1}, \"linenos\"\
: false} -->\n\n````python\n\n from azure.eventhub import EventData\n \
\ event_data_batch = await producer.create_batch()\n while True:\n \
\ try:\n event_data_batch.add(EventData('Message inside\
\ EventBatchData'))\n except ValueError:\n # The EventDataBatch\
\ object reaches its max_size.\n # You can send the full EventDataBatch\
\ object and create a new one here.\n break\n\n ````\n"
- uid: azure.eventhub.aio.EventHubProducerClient.flush
name: flush
summary: 'Buffered mode only.
Flush events in the buffer to be sent immediately if the client is working in
buffered mode.'
signature: 'async flush(**kwargs: Any) -> None'
keywordOnlyParameters:
- name: timeout
description: Timeout to flush the buffered events, default is None which means
no timeout.
types:
- <xref:float>
- <xref:None>
return:
types:
- <xref:None>
exceptions:
- type: azure.eventhub.exceptions.EventDataSendError
description: 'If the producer fails to flush the buffer within the given timeout
in buffered mode.'
- uid: azure.eventhub.aio.EventHubProducerClient.from_connection_string
name: from_connection_string
summary: Create an EventHubProducerClient from a connection string.
signature: 'from_connection_string(conn_str: str, *, eventhub_name: str | None =
None, buffered_mode: bool = False, on_error: Callable[[List[EventData | AmqpAnnotatedMessage],
str | None, Exception], Awaitable[None]] | None = None, on_success: Callable[[List[EventData
| AmqpAnnotatedMessage], str | None], Awaitable[None]] | None = None, max_buffer_length:
int | None = None, max_wait_time: float | None = None, logging_enable: bool =
False, http_proxy: Dict[str, str | int] | None = None, auth_timeout: float = 60,
user_agent: str | None = None, retry_total: int = 3, transport_type: TransportType
= TransportType.Amqp, **kwargs: Any) -> EventHubProducerClient'
parameters:
- name: conn_str
description: The connection string of an Event Hub.
isRequired: true
types:
- <xref:str>
keywordOnlyParameters:
- name: eventhub_name
description: The path of the specific Event Hub to connect the client to.
types:
- <xref:str>
- name: buffered_mode
description: 'If True, the producer client will collect events in a buffer, efficiently
batch,
then publish. Default is False.'
types:
- <xref:bool>
- name: on_success
description: 'The callback to be called once a batch has been successfully published.
The callback takes two parameters:
- *events*: The list of events that have been successfully published
- *partition_id*: The partition id that the events in the list have been published
to.
The callback function should be defined like: *on_success(events, partition_id)*.
It is required when *buffered_mode* is True while optional if *buffered_mode*
is False.'
types:
- <xref:typing.Optional>[<xref:typing.Callable>[[<xref:SendEventTypes>, <xref:typing.Optional>[<xref:str>]],
<xref:typing.Awaitable>[<xref:None>]]]
- name: on_error
description: 'The callback to be called once a batch has failed to be published.
The callback function should be defined like: *on_error(events, partition_id,
error)*, where:
- *events*: The list of events that failed to be published,
- *partition_id*: The partition id that the events in the list have been tried
to be published to and
- *error*: The exception related to the sending failure.
If *buffered_mode* is False, *on_error* callback is optional and errors will
be handled as follows:
- If an *on_error* callback is passed during the producer client instantiation,
then error information will be passed to the *on_error* callback, which will
then be called.
- If an *on_error* callback is not passed in during client instantiation,
then the error will be raised by default.
If *buffered_mode* is True, *on_error* callback is required and errors will
be handled as follows:
- If events fail to enqueue within the given timeout, then an error will be
directly raised.
- If events fail to send after enqueuing successfully, the *on_error* callback
will be called.'
types:
- <xref:typing.Optional>[<xref:typing.Callable>[[<xref:SendEventTypes>, <xref:typing.Optional>[<xref:str>],
<xref:Exception>], <xref:typing.Awaitable>[<xref:None>]]]
- name: max_buffer_length
description: 'Buffered mode only.
The total number of events per partition that can be buffered before a flush
will be triggered.
The default value is 1500 in buffered mode.'
types:
- <xref:int>
- name: max_wait_time
description: 'Buffered mode only.
The amount of time to wait for a batch to be built with events in the buffer
before publishing.
The default value is 1 in buffered mode.'
types:
- <xref:typing.Optional>[<xref:float>]
- name: logging_enable
description: Whether to output network trace logs to the logger. Default is *False*.
types:
- <xref:bool>
- name: http_proxy
description: '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''*.'
types:
- <xref:dict>
- name: auth_timeout
description: '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.'
defaultValue: '60'
types:
- <xref:float>
- name: user_agent
description: If specified, this will be added in front of the user agent string.
types:
- <xref:str>
- name: retry_total
description: 'The total number of attempts to redo a failed operation when an
error occurs.
Default value is 3.'
defaultValue: '3'
types:
- <xref:int>
- name: retry_backoff_factor
description: 'A backoff factor to apply between attempts after the second try
(most errors are resolved immediately by a second try without a delay).
In fixed mode, retry policy will always sleep for {backoff factor}.
In ''exponential'' mode, retry policy will sleep for: *{backoff factor} * (2
** ({number of total retries} - 1))*
seconds. If the backoff_factor is 0.1, then the retry will sleep
for [0.0s, 0.2s, 0.4s, ...] between retries. The default value is 0.8.'
types:
- <xref:float>
- name: retry_backoff_max
description: The maximum back off time. Default value is 120 seconds (2 minutes).
types:
- <xref:float>
- name: retry_mode
description: 'The delay behavior between retry attempts. Supported values are
''fixed'' or ''exponential'',
where default is ''exponential''.'
types:
- <xref:str>
- name: idle_timeout
description: 'Timeout, in seconds, after which this client will close the underlying
connection
if there is no activity. By default the value is None, meaning that the client
will not shutdown due to
inactivity unless initiated by the service.'
types:
- <xref:float>
- name: transport_type
description: 'The type of transport protocol that will be used for communicating
with
the Event Hubs service. Default is *TransportType.Amqp* in which case port 5671
is used.
If the port 5671 is unavailable/blocked in the network environment, *TransportType.AmqpOverWebsocket*
could
be used instead which uses port 443 for communication.'
defaultValue: TransportType.Amqp
types:
- <xref:azure.eventhub.TransportType>
- name: custom_endpoint_address
description: 'The custom endpoint address to use for establishing a connection
to
the Event Hubs service, allowing network requests to be routed through any application
gateways or
other paths needed for the host environment. Default is None.
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
If port is not specified in the *custom_endpoint_address*, by default port 443
will be used.'
types:
- <xref:typing.Optional>[<xref:str>]
- name: connection_verify
description: 'Path to the custom CA_BUNDLE file of the SSL certificate which is
used to
authenticate the identity of the connection endpoint.
Default is None in which case *certifi.where()* will be used.'
types:
- <xref:typing.Optional>[<xref:str>]
- name: uamqp_transport
description: 'Whether to use the *uamqp* library as the underlying transport.
The default value is
False and the Pure Python AMQP library will be used as the underlying transport.'
types:
- <xref:bool>
return:
types:
- <xref:azure.eventhub.aio.EventHubProducerClient>
examples:
- "Create a new instance of the EventHubProducerClient from connection string.<!--[!code-python[Main](les\\\
async_samples\\sample_code_eventhub_async.py )]-->\n\n<!-- literal_block {\"ids\"\
: [], \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\": [], \"source\"\
: \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.9\\\\x64\\\\Lib\\\\site-packages\\\
\\py2docfx\\\\dist_temp\\\\43\\\\azure-eventhub-5.11.7\\\\samples\\\\async_samples\\\
\\sample_code_eventhub_async.py\", \"xml:space\": \"preserve\", \"force\": false,\
\ \"language\": \"python\", \"highlight_args\": {\"linenostart\": 1}, \"linenos\"\
: false} -->\n\n````python\n\n import os\n from azure.eventhub.aio import\
\ EventHubProducerClient\n event_hub_connection_str = os.environ['EVENT_HUB_CONN_STR']\n\
\ eventhub_name = os.environ['EVENT_HUB_NAME']\n producer = EventHubProducerClient.from_connection_string(\n\
\ conn_str=event_hub_connection_str,\n eventhub_name=eventhub_name\
\ # EventHub name should be specified if it doesn't show up in connection string.\n\
\ )\n\n ````\n"
- uid: azure.eventhub.aio.EventHubProducerClient.get_buffered_event_count
name: get_buffered_event_count
summary: "The number of events that are buffered and waiting to be published for\
\ a given partition.\n Returns None in non-buffered mode. **NOTE: The event\
\ buffer is processed in a background\n coroutine, therefore the number of events\
\ in the buffer reported by this API should be\n considered only an approximation\
\ and is only recommend for use in debugging. For a\n partition ID that has\
\ no events buffered, 0 will be returned regardless of whether that\n partition\
\ ID actually exists within the Event Hub.**"
signature: 'get_buffered_event_count(partition_id: str) -> int | None'
parameters:
- name: partition_id
description: The target partition ID.
isRequired: true
types:
- <xref:str>
return:
types:
- <xref:int>
- <xref:None>
- uid: azure.eventhub.aio.EventHubProducerClient.get_eventhub_properties
name: get_eventhub_properties
summary: "Get properties of the Event Hub.\n\nKeys in the returned dictionary include:\n\
\n * *eventhub_name* (str) \n\n * *created_at* (UTC datetime.datetime) \n\n\
\ * *partition_ids* (list[str])"
signature: async get_eventhub_properties() -> Dict[str, Any]
return:
description: A dictionary containing information about the Event Hub.
types:
- <xref:dict>[<xref:str>, <xref:any>]
exceptions:
- type: azure.eventhub.exceptions.EventHubError
- uid: azure.eventhub.aio.EventHubProducerClient.get_partition_ids
name: get_partition_ids
summary: Get partition IDs of the Event Hub.
signature: async get_partition_ids() -> List[str]
return:
description: A list of partition IDs.
types:
- <xref:list>[<xref:str>]
exceptions:
- type: azure.eventhub.exceptions.EventHubError
- uid: azure.eventhub.aio.EventHubProducerClient.get_partition_properties
name: get_partition_properties
summary: "Get properties of the specified partition.\n\nKeys in the properties dictionary\
\ include:\n\n * *eventhub_name* (str) \n\n * *id* (str) \n\n * *beginning_sequence_number*\
\ (int) \n\n * *last_enqueued_sequence_number* (int) \n\n * *last_enqueued_offset*\
\ (str) \n\n * *last_enqueued_time_utc* (UTC datetime.datetime) \n\n * *is_empty*\
\ (bool)"
signature: 'async get_partition_properties(partition_id: str) -> Dict[str, Any]'
parameters:
- name: partition_id
description: The target partition ID.
isRequired: true
types:
- <xref:str>
return:
description: A dict of partition properties.
types:
- <xref:dict>[<xref:str>, <xref:any>]
exceptions:
- type: azure.eventhub.exceptions.EventHubError
- uid: azure.eventhub.aio.EventHubProducerClient.send_batch
name: send_batch
summary: "Sends a batch of event data.\nBy default, the method will block until\
\ acknowledgement is received or operation times out.\nIf the *EventHubProducerClient*\
\ is configured to run in buffered mode, the method will enqueue the events\n\
into local buffer and return. The producer will do automatic sending in the background.\n\
\nIf *buffered_mode* is False, *on_error* callback is optional and errors will\
\ be handled as follows:\n * If an *on_error* callback is passed during the\
\ producer client instantiation,\n\n then error information will be passed\
\ to the *on_error* callback, which will then be called.\n\n * If an *on_error*\
\ callback is not passed in during client instantiation,\n\n then the error\
\ will be raised by default.\n\nIf *buffered_mode* is True, *on_error* callback\
\ is required and errors will be handled as follows:\n * If events fail to enqueue\
\ within the given timeout, then an error will be directly raised. \n\n * If\
\ events fail to send after enqueuing successfully, the *on_error* callback will\
\ be called. \n\nIn buffered mode, sending a batch will remain intact and sent\
\ as a single unit.\nThe batch will not be rearranged. This may result in inefficiency\
\ of sending events.\n\nIf you're sending a finite list of *EventData* or *AmqpAnnotatedMessage*\
\ and you know it's within the\nevent hub frame size limit, you can send them\
\ with a *send_batch* call. Otherwise, use <xref:azure.eventhub.aio.EventHubProducerClient.create_batch>\n\
to create *EventDataBatch* and add either *EventData* or *AmqpAnnotatedMessage*\
\ into the batch one by one\nuntil the size limit, and then call this method to\
\ send out the batch."
signature: 'async send_batch(event_data_batch: EventDataBatch | List[EventData |
AmqpAnnotatedMessage], **kwargs: Any) -> None'
parameters:
- name: event_data_batch
description: 'The *EventDataBatch* object to be sent or a list of *EventData*
to be sent in a batch.
All *EventData* or *AmqpAnnotatedMessage* in the list or *EventDataBatch* will
land on the same partition.'
isRequired: true
types:
- <xref:typing.Union>[<xref:azure.eventhub.EventDataBatch>, <xref:typing.List>[<xref:typing.Union>[<xref:azure.eventhub.EventData>,
<xref:azure.eventhub.amqp.AmqpAnnotatedMessage>]]
keywordOnlyParameters:
- name: timeout
description: 'The maximum wait time to send the event data in non-buffered mode
or the
maximum wait time to enqueue the event data into the buffer in buffered mode.
In non-buffered mode, the default wait time specified when the producer
was created will be used. In buffered mode, the default wait time is None.'
types:
- <xref:float>
- name: partition_id
description: 'The specific partition ID to send to. Default is None, in which
case the service
will assign to all partitions using round-robin.
A *TypeError* will be raised if partition_id is specified and event_data_batch
is an *EventDataBatch* because
*EventDataBatch* itself has partition_id.'
types:
- <xref:str>
- name: partition_key
description: 'With the given partition_key, event data will be sent to
a particular partition of the Event Hub decided by the service.
A *TypeError* will be raised if partition_key is specified and event_data_batch
is an *EventDataBatch* because
*EventDataBatch* itself has partition_key.
If both partition_id and partition_key are provided, the partition_id will take
precedence.
**WARNING: Setting partition_key of non-string value on the events to be sent
is discouraged
as the partition_key will be ignored by the Event Hub service and events will
be assigned
to all partitions using round-robin. Furthermore, there are SDKs for consuming
events which expect
partition_key to only be string type, they might fail to parse the non-string
value.**'
types:
- <xref:str>
return:
types:
- <xref:None>
exceptions:
- type: azure.eventhub.exceptions.AuthenticationError
- type: azure.eventhub.exceptions.ConnectError
- type: azure.eventhub.exceptions.ConnectionLostError
- type: azure.eventhub.exceptions.EventDataError
- type: azure.eventhub.exceptions.EventDataSendError
- type: azure.eventhub.exceptions.EventHubError
- type: ValueError
- type: TypeError
- type: azure.eventhub.exceptions.OperationTimeoutError
description: 'If the value specified by the timeout parameter elapses before the
event can be
sent in non-buffered mode or the events can be enqueued into the buffered in
buffered mode.'
examples:
- "Asynchronously sends event data<!--[!code-python[Main](les\\async_samples\\sample_code_eventhub_async.py\
\ )]-->\n\n<!-- literal_block {\"ids\": [], \"classes\": [], \"names\": [], \"\
dupnames\": [], \"backrefs\": [], \"source\": \"C:\\\\hostedtoolcache\\\\windows\\\
\\Python\\\\3.11.9\\\\x64\\\\Lib\\\\site-packages\\\\py2docfx\\\\dist_temp\\\\\
43\\\\azure-eventhub-5.11.7\\\\samples\\\\async_samples\\\\sample_code_eventhub_async.py\"\
, \"xml:space\": \"preserve\", \"force\": false, \"language\": \"python\", \"\
highlight_args\": {\"linenostart\": 1}, \"linenos\": false} -->\n\n````python\n\
\n async with producer:\n event_data_batch = await producer.create_batch()\n\
\ while True:\n try:\n event_data_batch.add(EventData('Message\
\ inside EventBatchData'))\n except ValueError:\n \
\ # The EventDataBatch object reaches its max_size.\n #\
\ You can send the full EventDataBatch object and create a new one here.\n \
\ break\n await producer.send_batch(event_data_batch)\n\
\n ````\n"
- uid: azure.eventhub.aio.EventHubProducerClient.send_event
name: send_event
summary: "Sends an event data.\nBy default, the method will block until acknowledgement\
\ is received or operation times out.\nIf the *EventHubProducerClient* is configured\
\ to run in buffered mode, the method will enqueue the event\ninto local buffer\
\ and return. The producer will do automatic batching and sending in the background.\n\
\n If *buffered_mode* is False, *on_error* callback is optional and errors will\
\ be handled as follows:\n * If an *on_error* callback is passed during the\
\ producer client instantiation,\n\n then error information will be\
\ passed to the *on_error* callback, which will then be called.\n\n * If\
\ an *on_error* callback is not passed in during client instantiation,\n\n \
\ then the error will be raised by default.\n\n If *buffered_mode* is\
\ True, *on_error* callback is required and errors will be handled as follows:\n\
\ * If events fail to enqueue within the given timeout, then an error will\
\ be directly raised. \n\n * If events fail to send after enqueuing successfully,\
\ the *on_error* callback will be called."
signature: 'async send_event(event_data: EventData | AmqpAnnotatedMessage, **kwargs:
Any) -> None'
parameters:
- name: event_data
description: The *EventData* object to be sent.
isRequired: true
types:
- <xref:typing.Union>[<xref:azure.eventhub.EventData>, <xref:azure.eventhub.amqp.AmqpAnnotatedMessage>]
keywordOnlyParameters:
- name: timeout
description: 'The maximum wait time to send the event data in non-buffered mode
or the
maximum wait time to enqueue the event data into the buffer in buffered mode.
In non-buffered mode, the default wait time specified when the producer
was created will be used. In buffered mode, the default wait time is None indicating
that the event will be
scheduled to send immediately.'
types:
- <xref:float>
- name: partition_id
description: 'The specific partition ID to send to. Default is None, in which
case the service
will assign to all partitions using round-robin.
A *TypeError* will be raised if partition_id is specified and event_data_batch
is an *EventDataBatch* because
*EventDataBatch* itself has partition_id.'
types:
- <xref:str>
- name: partition_key
description: 'With the given partition_key, event data will be sent to
a particular partition of the Event Hub decided by the service.
A *TypeError* will be raised if partition_key is specified and event_data_batch
is an *EventDataBatch* because
*EventDataBatch* itself has partition_key.
If both partition_id and partition_key are provided, the partition_id will take
precedence.
**WARNING: Setting partition_key of non-string value on the events to be sent
is discouraged
as the partition_key will be ignored by the Event Hub service and events will
be assigned
to all partitions using round-robin. Furthermore, there are SDKs for consuming
events which expect
partition_key to only be string type, they might fail to parse the non-string
value.**'
types:
- <xref:str>
return:
types:
- <xref:None>
exceptions:
- type: azure.eventhub.exceptions.AuthenticationError
- type: azure.eventhub.exceptions.ConnectError
- type: azure.eventhub.exceptions.ConnectionLostError
- type: azure.eventhub.exceptions.EventDataError
- type: azure.eventhub.exceptions.EventDataSendError
- type: azure.eventhub.exceptions.EventHubError
- type: azure.eventhub.exceptions.OperationTimeoutError
description: 'If the value specified by the timeout parameter elapses before the
event can be
sent in non-buffered mode or the events can not be enqueued into the buffered
in buffered mode.'
attributes:
- uid: azure.eventhub.aio.EventHubProducerClient.total_buffered_event_count
name: total_buffered_event_count
summary: "The total number of events that are currently buffered and waiting to\
\ be published,\n across all partitions. Returns None in non-buffered mode.\
\ **NOTE: The event buffer\n is processed in a background coroutine, therefore\
\ the number of events in the buffer\n reported by this API should be considered\
\ only an approximation and is only recommend\n for use in debugging.**"
return:
types:
- <xref:int>
- <xref:None>