Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KafkaConnection

Kafka connection using plain driver.

By defining a connection and sharing it through multiple message queues you can reduce number of used database connections.

Configuration parameters

  • client_id: (optional) name of the client id
  • connection(s):
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • host: host name or IP address
    • port: port number (default: 27017)
    • uri: resource URI or connection string with all parameters in it
  • credential(s):
    • store_key: (optional) a key to retrieve the credentials from ICredentialStore
    • username: user name
    • password: user password
  • options:
    • log_level: (optional) log level 0 - None, 1 - Error, 2 - Warn, 3 - Info, 4 - Debug (default: 1)
    • connect_timeout: (optional) number of milliseconds to connect to broker (default: 1000)
    • max_retries: (optional) maximum retry attempts (default: 5)
    • retry_timeout: (optional) number of milliseconds to wait on each reconnection attempt (default: 30000)
    • request_timeout: (optional) number of milliseconds to wait on flushing messages (default: 30000)

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages
  • *:discovery:*:*:1.0 (optional) IDiscovery services
  • *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials

Hierarchy

  • KafkaConnection

Implements

  • any
  • any
  • any
  • any

Index

Constructors

constructor

  • Creates a new instance of the connection component.

    Returns KafkaConnection

Properties

Protected _adminClient

_adminClient: any

The Kafka admin client object;

Protected _clientConfig

_clientConfig: any

Kafka connection properties

Protected _clientId

_clientId: string = os.hostname()

Protected _connectTimeout

_connectTimeout: number = 1000

Protected _connection

_connection: any

The Kafka connection pool object.

Protected _connectionResolver

_connectionResolver: KafkaConnectionResolver = new KafkaConnectionResolver()

The connection resolver.

Protected _logLevel

_logLevel: number = 1

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

The logger.

Protected _maxRetries

_maxRetries: number = 5

Protected _options

_options: ConfigParams = new ConfigParams()

The configuration options.

Protected _producer

_producer: any

The Kafka message producer object;

Protected _requestTimeout

_requestTimeout: number = 30000

Protected _retryTimeout

_retryTimeout: number = 30000

Protected _subscriptions

_subscriptions: KafkaSubscription[] = []

Topic subscriptions

Methods

Protected checkOpen

  • checkOpen(): any
  • Checks if connection is open

    Returns any

    an error is connection is closed or null otherwise.

close

  • close(correlationId: string, callback?: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

commit

  • commit(topic: string, groupId: string, partition: number, offset: number, listener: IKafkaMessageListener, callback?: function): void
  • Commit a message offset.

    Parameters

    • topic: string

      a topic name

    • groupId: string

      (optional) a consumer group id

    • partition: number

      a partition number

    • offset: number

      a message offset

    • listener: IKafkaMessageListener

      a message listener

    • Optional callback: function

      (optional) callback to receive notification on operation result

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

Protected connectToAdmin

  • connectToAdmin(callback: function): void
  • Connect admin client on demand.

    Parameters

    • callback: function

      a callback to get notification on connection result.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

createQueue

  • createQueue(name: string, callback: function): void
  • Creates a message queue. If connection doesn't support this function it exists without error.

    Parameters

    • name: string

      the name of the queue to be created.

    • callback: function

      notifies about completion with error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

deleteQueue

  • deleteQueue(name: string, callback: function): void
  • Deletes a message queue. If connection doesn't support this function it exists without error.

    Parameters

    • name: string

      the name of the queue to be deleted.

    • callback: function

      notifies about completion with error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

getConnection

  • getConnection(): any
  • Returns any

getProducer

  • getProducer(): any
  • Returns any

isOpen

  • isOpen(): boolean
  • Checks if the component is opened.

    Returns boolean

    true if the component has been opened and false otherwise.

open

  • open(correlationId: string, callback?: function): void
  • Opens the component.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

publish

  • publish(topic: string, messages: any[], options: any, callback?: function): void
  • Publish a message to a specified topic

    Parameters

    • topic: string

      a topic where the message will be placed

    • messages: any[]

      a list of messages to be published

    • options: any

      publishing options

    • Optional callback: function

      (optional) callback to receive notification on operation result

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

readQueueNames

  • readQueueNames(callback: function): void
  • Reads a list of registered queue names. If connection doesn't support this function returnes an empty list.

    callback

    to receive a list with registered queue names or an error.

    Parameters

    • callback: function
        • (err: any, queueNames: string[]): void
        • Parameters

          • err: any
          • queueNames: string[]

          Returns void

    Returns void

seek

  • seek(topic: string, groupId: string, partition: number, offset: number, listener: IKafkaMessageListener, callback?: function): void
  • Seek a message offset.

    Parameters

    • topic: string

      a topic name

    • groupId: string

      (optional) a consumer group id

    • partition: number

      a partition number

    • offset: number

      a message offset

    • listener: IKafkaMessageListener

      a message listener

    • Optional callback: function

      (optional) callback to receive notification on operation result

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

subscribe

  • subscribe(topic: string, groupId: string, options: any, listener: IKafkaMessageListener, callback?: function): void
  • Subscribe to a topic

    Parameters

    • topic: string
    • groupId: string

      (optional) a consumer group id

    • options: any

      subscription options

    • listener: IKafkaMessageListener

      a message listener

    • Optional callback: function

      (optional) callback to receive notification on operation result

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

unsubscribe

  • unsubscribe(topic: string, groupId: string, listener: IKafkaMessageListener, callback?: function): void
  • Unsubscribe from a previously subscribed topic

    Parameters

    • topic: string

      a topic name

    • groupId: string

      (optional) a consumer group id

    • listener: IKafkaMessageListener

      a message listener

    • Optional callback: function

      (optional) callback to receive notification on operation result

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc