@biorate/rdkafka
Version:
Rdkafka connector
49 lines (48 loc) • 1.41 kB
text/typescript
import { injectable } from '@biorate/inversion';
import { Connector } from '@biorate/connector';
import { RDKafkaProducerStreamCantConnectError } from '../errors';
import { RDKafkaProducerStreamConnection } from '../connections';
import {
IRDKafkaProducerStreamConfig,
IRDKafkaProducerStreamConnection,
} from '../interfaces';
/**
* @description RDKafka producer stream connector
*
* ### Features:
* - Producer stream connector manager for node-rdkafka
*
* @example
* ```
* ```
*/
()
export class RDKafkaProducerStreamConnector extends Connector<
IRDKafkaProducerStreamConfig,
IRDKafkaProducerStreamConnection
> {
/**
* @description Private connections storage
*/
private '#connections': Map<string, IRDKafkaProducerStreamConnection>;
/**
* @description Private link to selected (used) connection
*/
private '#current': IRDKafkaProducerStreamConnection | undefined;
/**
* @description Namespace path for fetching configuration
*/
protected readonly namespace = 'RDKafkaProducerStream';
/**
* @description Create connection
*/
protected async connect(config: IRDKafkaProducerStreamConfig) {
let connection: IRDKafkaProducerStreamConnection;
try {
connection = new RDKafkaProducerStreamConnection(config);
} catch (e: unknown) {
throw new RDKafkaProducerStreamCantConnectError(<Error>e);
}
return connection;
}
}