Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventHubConsumerClient

Package version

class

The EventHubConsumerClient is the main point of interaction for consuming events in Azure Event Hubs service.

There are multiple ways to create an EventHubConsumerClient

  • 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

  • EventHubConsumerClient

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 EventHubConsumerClient

  • 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 EventHubConsumerClient

  • 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 EventHubConsumerClient

Properties

Static defaultConsumerGroupName

defaultConsumerGroupName: string = Constants.defaultConsumerGroup
property

The name of the default consumer group in the Event Hubs service.

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

getPartitionIds

  • getPartitionIds(): Promise<string[]>
  • 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.

    Returns Promise<string[]>

    A promise that resolves with an Array of strings.

getPartitionProperties

  • Provides information about the specified partition.

    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<PartitionProperties>

    A promise that resoloves with PartitionProperties.

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.

subscribe

  • Subscribe to all messages from all available partitions.

    Use this overload if you want to read from all partitions and not coordinate with other subscribers.

    Parameters

    • consumerGroupName: string

      The name of the consumer group from which you want to process events.

    • onReceivedEvents: OnReceivedEvents

      Called when new events are received.

    • Optional options: SubscriptionOptions

      Options to handle additional events related to partitions (errors, opening, closing) as well as batch sizing.

    Returns Subscription

  • Subscribe to all messages from a subset of partitions.

    Use this overload if you want to read from a specific set of partitions and not coordinate with other subscribers.

    Parameters

    • consumerGroupName: string

      The name of the consumer group from which you want to process events.

    • onReceivedEvents: OnReceivedEvents

      Called when new events are received.

    • partitionId: string

      A partition id to subscribe to.

    • Optional options: SubscriptionOptions

      Options to handle additional events related to partitions (errors, opening, closing) as well as batch sizing.

    Returns Subscription

  • Subscribes to multiple partitions.

    Use this overload if you want to coordinate with other subscribers using a PartitionManager

    Parameters

    • consumerGroupName: string

      The name of the consumer group from which you want to process events.

    • onReceivedEvents: OnReceivedEvents

      Called when new events are received. This is also a good place to update checkpoints as appropriate.

    • partitionManager: PartitionManager

      A partition manager that manages ownership information and checkpoint details.

    • Optional options: SubscriptionOptions

      Options to handle additional events related to partitions (errors, opening, closing) as well as batch sizing.

    Returns Subscription

Generated using TypeDoc