Child client support (#768)
With this pr we introduce the `client.child` API, which returns a new client instance that shares the connection pool with the parent client.
This feature can be handy if you need to have multiple client instances with different configurations, but with a shared connection pool.
Example:
```js
const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
const child = client.child({
headers: { 'x-foo': 'bar' },
requestTimeout: 1000
})
client.info(console.log)
child.info(console.log)
```
**Open questions:**
* Currently, the event emitter is shared between the parent and the child(ren), is it ok?
* Currently, if you extend the parent client, the child client will have the same extensions, while if the child client adds an extension, the parent client will not be extended. Is it ok?
**Caveats:**
* You can override _any_ option except for the connection pool specific options (`ssl`, `agent`, `pingTimeout`, `Connection`, and `resurrectStrategy`).
* You can't specify a new `Connection` class.
* If you call `close` in any of the parent/child clients, every client will be closed.
_Note: the `nodeFilter` and `nodeSelector` options are now `Transport` options and no longer `ConnectionPool` options._
This commit is contained in:
committed by
GitHub
parent
66e8d61476
commit
5b856cd4c2
13
lib/ConnectionPool.d.ts
vendored
13
lib/ConnectionPool.d.ts
vendored
@ -2,14 +2,7 @@
|
||||
|
||||
import { SecureContextOptions } from 'tls';
|
||||
import Connection, { AgentOptions } from './Connection';
|
||||
|
||||
export interface nodeSelectorFn {
|
||||
(connections: Connection[]): Connection;
|
||||
}
|
||||
|
||||
export interface nodeFilterFn {
|
||||
(connection: Connection): boolean;
|
||||
}
|
||||
import { nodeFilterFn, nodeSelectorFn } from './Transport';
|
||||
|
||||
interface ConnectionPoolOptions {
|
||||
ssl?: SecureContextOptions;
|
||||
@ -17,8 +10,6 @@ interface ConnectionPoolOptions {
|
||||
pingTimeout?: number;
|
||||
Connection: typeof Connection;
|
||||
resurrectStrategy?: string;
|
||||
nodeFilter?: nodeFilterFn;
|
||||
nodeSelector?: string | nodeSelectorFn;
|
||||
}
|
||||
|
||||
export interface getConnectionOptions {
|
||||
@ -46,8 +37,6 @@ export default class ConnectionPool {
|
||||
resurrectTimeout: number;
|
||||
resurrectTimeoutCutoff: number;
|
||||
pingTimeout: number;
|
||||
nodeFilter: nodeFilterFn;
|
||||
nodeSelector: nodeSelectorFn;
|
||||
Connection: typeof Connection;
|
||||
resurrectStrategy: number;
|
||||
constructor(opts?: ConnectionPoolOptions);
|
||||
|
||||
Reference in New Issue
Block a user