UNPKG

3.23 kBTypeScriptView Raw
1import { ConfigParams } from 'pip-services3-commons-node';
2import { IReconfigurable } from 'pip-services3-commons-node';
3import { ConnectionParams } from './ConnectionParams';
4import { IDiscovery } from './IDiscovery';
5/**
6 * Discovery service that keeps connections in memory.
7 *
8 * ### Configuration parameters ###
9 *
10 * - [connection key 1]:
11 * - ... connection parameters for key 1
12 * - [connection key 2]:
13 * - ... connection parameters for key N
14 *
15 * @see [[IDiscovery]]
16 * @see [[ConnectionParams]]
17 *
18 * ### Example ###
19 *
20 * let config = ConfigParams.fromTuples(
21 * "key1.host", "10.1.1.100",
22 * "key1.port", "8080",
23 * "key2.host", "10.1.1.100",
24 * "key2.port", "8082"
25 * );
26 *
27 * let discovery = new MemoryDiscovery();
28 * discovery.readConnections(config);
29 *
30 * discovery.resolve("123", "key1", (err, connection) => {
31 * // Result: host=10.1.1.100;port=8080
32 * });
33 */
34export declare class MemoryDiscovery implements IDiscovery, IReconfigurable {
35 private _items;
36 /**
37 * Creates a new instance of discovery service.
38 *
39 * @param config (optional) configuration with connection parameters.
40 */
41 constructor(config?: ConfigParams);
42 /**
43 * Configures component by passing configuration parameters.
44 *
45 * @param config configuration parameters to be set.
46 */
47 configure(config: ConfigParams): void;
48 /**
49 * Reads connections from configuration parameters.
50 * Each section represents an individual Connectionparams
51 *
52 * @param config configuration parameters to be read
53 */
54 readConnections(config: ConfigParams): void;
55 /**
56 * Registers connection parameters into the discovery service.
57 *
58 * @param correlationId (optional) transaction id to trace execution through call chain.
59 * @param key a key to uniquely identify the connection parameters.
60 * @param credential a connection to be registered.
61 * @param callback callback function that receives a registered connection or error.
62 */
63 register(correlationId: string, key: string, connection: ConnectionParams, callback: (err: any, result: ConnectionParams) => void): void;
64 /**
65 * Resolves a single connection parameters by its key.
66 *
67 * @param correlationId (optional) transaction id to trace execution through call chain.
68 * @param key a key to uniquely identify the connection.
69 * @param callback callback function that receives found connection or error.
70 */
71 resolveOne(correlationId: string, key: string, callback: (err: any, result: ConnectionParams) => void): void;
72 /**
73 * Resolves all connection parameters by their key.
74 *
75 * @param correlationId (optional) transaction id to trace execution through call chain.
76 * @param key a key to uniquely identify the connections.
77 * @param callback callback function that receives found connections or error.
78 */
79 resolveAll(correlationId: string, key: string, callback: (err: any, result: ConnectionParams[]) => void): void;
80}