Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventHubProducerClient

Package version

class

The client is the main point of interaction with Azure Event Hubs service. It offers connection to a specific Event Hub within the Event Hubs namespace along with operations for sending event data and inspecting the connected Event Hub.

There are multiple ways to create an EventHubProducerClient

  • Use the connection string from the SAS policy created for your Event Hub instance.
  • Use the connection string from the SAS policy created for your Event Hub namespace, and the name of the Event Hub instance
  • Use the fully qualified domain name of your Event Hub namespace like <yournamespace>.servicebus.windows.net, and a credentials object.

Hierarchy

  • EventHubProducerClient

Index

Constructors

constructor

  • constructor

    Parameters

    • connectionString: string

      The connection string to use for connecting to the Event Hubs namespace. It is expected that the shared key properties and the Event Hub path are contained in this connection string. e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.

    • Optional options: EventHubClientOptions

      A set of options to apply when configuring the client.

      • dataTransformer: A set of encode/decode methods to be used to encode an event before sending to service and to decode the event received from the service
      • userAgent : A string to append to the built in user agent string that is passed as a connection property to the service.
      • websocket : The WebSocket constructor used to create an AMQP connection if you choose to make the connection over a WebSocket.
      • webSocketConstructorOptions : Options to pass to the Websocket constructor when you choose to make the connection over a WebSocket.
      • retryOptions : The retry options for all the operations on the client/producer/consumer. A simple usage can be { "maxRetries": 4 }.

    Returns EventHubProducerClient

  • constructor

    Parameters

    • connectionString: string

      The connection string to use for connecting to the Event Hubs namespace. It is expected that the shared key properties and the Event Hub path are contained in this connection string. e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.

    • eventHubName: string

      The path of the specific Event Hub to connect the client to.

    • Optional options: EventHubClientOptions

      A set of options to apply when configuring the client.

      • dataTransformer: A set of encode/decode methods to be used to encode an event before sending to service and to decode the event received from the service
      • userAgent : A string to append to the built in user agent string that is passed as a connection property to the service.
      • websocket : The WebSocket constructor used to create an AMQP connection if you choose to make the connection over a WebSocket.
      • webSocketConstructorOptions : Options to pass to the Websocket constructor when you choose to make the connection over a WebSocket.
      • retryOptions : The retry options for all the operations on the client/producer/consumer. A simple usage can be { "maxRetries": 4 }.

    Returns EventHubProducerClient

  • constructor

    Parameters

    • host: string

      The fully qualified host name for the Event Hubs namespace. This is likely to be similar to .servicebus.windows.net

    • eventHubName: string

      The path of the specific Event Hub to connect the client to.

    • credential: TokenCredential

      SharedKeyCredential object or your credential that implements the TokenCredential interface.

    • Optional options: EventHubClientOptions

      A set of options to apply when configuring the client.

      • dataTransformer: A set of encode/decode methods to be used to encode an event before sending to service and to decode the event received from the service
      • userAgent : A string to append to the built in user agent string that is passed as a connection property to the service.
      • websocket : The WebSocket constructor used to create an AMQP connection if you choose to make the connection over a WebSocket.
      • webSocketConstructorOptions : Options to pass to the Websocket constructor when you choose to make the connection over a WebSocket.
      • retryOptions : The retry options for all the operations on the client/producer/consumer. A simple usage can be { "maxRetries": 4 }.

    Returns EventHubProducerClient

Accessors

eventHubName

  • get eventHubName(): string
  • property
    readonly

    The name of the Event Hub instance for which this client is created.

    Returns string

fullyQualifiedNamespace

  • get fullyQualifiedNamespace(): string
  • property
    readonly

    The fully qualified Event Hubs namespace for which this client is created. This is likely to be similar to .servicebus.windows.net.

    Returns string

Methods

close

  • close(): Promise<void>
  • Closes the AMQP connection to the Event Hub instance, returning a promise that will be resolved when disconnection is completed.

    throws

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

    Returns Promise<void>

    Promise

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 sendBatch method of the EventHubProducerClient 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 operation.

    Returns Promise<EventDataBatch>

    Promise

getPartitionIds

  • Provides an array of partitionIds.

    throws

    {Error} Thrown if the underlying connection has been closed, create a new EventHubClient.

    throws

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

    Parameters

    Returns Promise<Array<string>>

    A promise that resolves with an Array of strings.

getProperties

  • Provides the Event Hub runtime information.

    throws

    {Error} Thrown if the underlying connection has been closed, create a new EventHubClient.

    throws

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

    Parameters

    Returns Promise<EventHubProperties>

    A promise that resolves with EventHubProperties.

sendBatch

  • Sends a batch 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.

    Parameters

    • batch: EventDataBatch

      An instance of EventDataBatch that you can create using the createBatch method.

    • Optional options: SendBatchOptions

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

      • abortSignal : A signal the request to cancel the send operation.

    Returns Promise<void>

    Promise

  • Sends a batch of events to the associated Event Hub to a specific partition

    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 the batch was created using a partitionKey as it conflicts with our attempt to send to a specific partition.

    Parameters

    • batch: EventDataBatch

      An instance of EventDataBatch that you can create using the createBatch method.

    • partitionId: string

      a partition id

    • Optional options: SendBatchOptions

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

      • abortSignal : A signal the request to cancel the send operation.

    Returns Promise<void>

    Promise

Generated using TypeDoc