Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventHubProducer

Package version

A producer responsible for sending events to an Event Hub. To create a producer use the createProducer() method on your EventHubClient. You can pass the below in the options when creating a producer.

  • partitionId : The identifier of the partition that the producer can be bound to.
  • retryOptions : The retry options used to govern retry attempts when an issue is encountered while sending events. A simple usage can be { "maxRetries": 4 }.

If partitionId is specified when creating a producer, all event data sent using the producer will be sent to the specified partition. Otherwise, they are automatically routed to an available partition by the Event Hubs service.

Automatic routing of partitions is recommended because:

  • The sending of events will be highly available.
  • The event data will be evenly distributed among all available partitions.
class

Hierarchy

  • EventHubProducer

Index

Accessors

Methods

Accessors

isClosed

  • get isClosed(): boolean
  • property

    Returns true if either the producer or the client that created it has been closed.

    readonly

    Returns boolean

Methods

close

  • close(): Promise<void>
  • Closes the underlying AMQP sender link. Once closed, the producer cannot be used for any further operations. Use the createProducer function on the EventHubClient to instantiate a new EventHubProducer.

    throws

    {Error} Thrown if the underlying connection encounters an error while closing.

    Returns Promise<void>

createBatch

  • Creates an instance of EventDataBatch to which one can add events until the maximum supported size is reached. The batch can be passed to the send() method of the EventHubProducer to be sent to Azure Event Hubs.

    Parameters

    • Optional options: CreateBatchOptions

      A set of options to configure the behavior of the batch.

      • partitionKey : A value that is hashed to produce a partition assignment. Not applicable if the EventHubProducer was created using a partitionId.
      • maxSizeInBytes: The upper limit for the size of batch. The tryAdd function will return false after this limit is reached.
      • abortSignal : A signal the request to cancel the send operation.

    Returns Promise<EventDataBatch>

    Promise

send

  • Send one or more of events to the associated Event Hub.

    throws

    {AbortError} Thrown if the operation is cancelled via the abortSignal.

    throws

    {MessagingError} Thrown if an error is encountered while sending a message.

    throws

    {TypeError} Thrown if a required parameter is missing.

    throws

    {Error} Thrown if the underlying connection or sender has been closed.

    throws

    {Error} Thrown if a partitionKey is provided when the producer was created with a partitionId.

    throws

    {Error} Thrown if batch was created with partitionKey different than the one provided in the options. Create a new producer using the EventHubClient createProducer method.

    Parameters

    • eventData: EventData | EventData[] | EventDataBatch

      An individual EventData object, or an array of EventData objects or an instance of EventDataBatch.

    • Default value options: SendOptions = {}

      The set of options that can be specified to influence the way in which events are sent to the associated Event Hub.

      • partitionKey : A value that is hashed to produce a partition assignment. Not applicable if the EventHubProducer was created using a partitionId.
      • abortSignal : A signal the request to cancel the send operation.

    Returns Promise<void>

    Promise

Generated using TypeDoc