Implements: IMessageQueueConnection, IReferenceable, IConfigurable, IOpenable
Description
By defining a connection and sharing it through multiple message queues you can reduce the number of used database connections.
Configuration parameters
- client_id: (optional) name of the client id
- connection(s):
- discovery_key: (optional) 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) key to retrieve the credentials from ICredentialStore
- username: username
- password: user’s 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
Constructors
Creates a new instance of the connection component.
publicconstructor()
Fields
Instance methods
checkOpen
Checks if the connection is open.
Raises an error is the connection is closed.
protectedcheckOpen(): void
close
Closes a component and frees used resources.
publicclose(correlationId: string): Promise<void>
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
commit
Commit a message offset.
publiccommit(topic: string, groupId: string, partition: number, offset: number, listener: IKafkaMessageListener): Promise<void>
- topic: string - topic name
- groupId: string - (optional) consumer group id
- partition: number - partition number
- offset: number - message offset
- listener: IKafkaMessageListener - message listener
configure
Configures the component by passing its configuration parameters.
publicconfigure(config: ConfigParams): void
- config: ConfigParams - configuration parameters to be set.
connectToAdmin
Connects an admin client on demand.
protectedconnectToAdmin(): Promise<void>
createQueue
Creates a message queue. If the connection doesn’t support this function, it exists without error.
publiccreateQueue(name: string): Promise<void>
- name: string - name of the queue to be created.
deleteQueue
Deletes a message queue. If the connection doesn’t support this function, it exists without error.
publicdeleteQueue(name: string): Promise<void>
- name: string - name of the queue to be deleted.
getConnection
Gets the connection.
publicgetConnection(): any
- returns: any - connection to a MySQL database
getProducer
Gets the Kafka message producer object
publicgetProducer(): any
- returns: any - producer object
isOpen
Checks if the component is opened.
publicisOpen(): boolean
- returns: boolean - true if the component is open and false otherwise.
open
Opens the component.
publicopen(correlationId: string): Promise<void>
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
publish
Publish a message to a specified topic.
publicpublish(topic: string, messages: any[], options: any): Promise<void>
- topic: string - topic where the message will be placed.
- messages: any[] - list of messages to be published.
- options: any - publishing options.
readQueueNames
Reads a list of registered queue names. If the connection doesn’t support this function, it returns an empty list.
publicreadQueueNames(): Promise<string[]>
- returns: Promise<string[]> - queue names.
seek
Seeks a message offset.
publicseek(topic: string, groupId: string, partition: number, offset: number, listener: IKafkaMessageListener): Promise<void>
- topic: string - topic name
- groupId: string - (optional) consumer group id
- partition: number - partition number
- offset: number - message offset
- listener: IKafkaMessageListener - message listener
setReferences
Sets references to dependent components.
publicsetReferences(references: IReferences): void
- references: IReferences - references to locate the component dependencies.
subscribe
Subscribes to a topic
publicsubscribe(topic: string, groupId: string, options: any, listener: IKafkaMessageListener): Promise<void>
- topic: string - subject(topic) name
- groupId: string - (optional) consumer group id
- options: any - subscription options
- listener: IKafkaMessageListener - message listener
unsubscribe
Unsubscribes from a previously subscribed topic
publicunsubscribe(topic: string, groupId: string, listener: IKafkaMessageListener): Promise<void>
- topic: string - topic name
- groupId: string - (optional) consumer group id
- listener: IKafkaMessageListener - message listener