# API `@deepkit/broker`

```sh
npm install @deepkit/broker
```

该包包含 Deepkit Broker 的抽象、服务器实现，以及作为适配器的多个客户端实现（`BrokerDeepkitAdapter`、`BrokerMemoryAdapter`）。

## API reference of @deepkit/broker

### BrokerConnection (class)

```typescript
export class BrokerConnection extends RpcKernelBaseConnection {
    constructor(stats: RpcStats, logger: Logger, transportConnection: TransportConnection, connections: RpcKernelConnections, injector: InjectorContext, eventDispatcher: EventDispatcher, protected state: BrokerState);
    close(): void;
    async onMessage(message: RpcMessage, response: RpcMessageBuilder): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/kernel.ts#L62

### BrokerState (class)

```typescript
export class BrokerState {
    /**
     * Simple key/value store.
     */
    keyStore;
    /**
     * Cache store.
     */
    cacheStore;
    subscriptions;
    entityFields;
    queues;
    locker;
    enableSnapshot;
    snapshotInterval;
    snapshotPath;
    snapshotting;
    /**
     * All connections in this list are notified about cache invalidations.
     */
    invalidationCacheMessageConnections: BrokerConnection[];
    getEntityFields(name: string): string[];
    publishEntityFields(name: string, fields: string[]): boolean;
    unsubscribeEntityFields(name: string, fields: string[]);
    lock(id: string, ttl: number, timeout: number = ): Promise<ProcessLock>;
    tryLock(id: string, ttl: number = ): Promise<ProcessLock | undefined>;
    isLocked(id: string): boolean;
    unsubscribe(channel: string, connection: BrokerConnection);
    subscribe(channel: string, connection: BrokerConnection);
    publish(channel: string, v: Uint8Array);
    queueSubscribe(queueName: string, connection: BrokerConnection, maxParallel: number);
    queueUnsubscribe(queueName: string, connection: BrokerConnection);
    queuePublish(body: BrokerQueuePublish);
    /**
     * When a queue message has been sent to a consumer and the consumer answers.
     */
    queueMessageHandled(queueName: string, connection: BrokerConnection, id: number, answer: {
        error?: string;
        success: boolean;
        delay?: number;
    });
    setCache(id: string, data: Uint8Array, ttl: number);
    getCache(id: string): {
        data: Uint8Array;
        ttl: number;
    } | undefined;
    deleteCache(id: string);
    increment(id: string, v?: number): number;
    setKey(id: string, data: Uint8Array, ttl: number);
    getKey(id: string): Uint8Array | undefined;
    deleteKey(id: string);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/kernel.ts#L304

### BrokerKernel (class)

```typescript
export class BrokerKernel extends RpcKernel {
    createConnection(transport: TransportConnection): BrokerConnection;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/kernel.ts#L569

### provideBusChannel (function)

Provides a bus channel for the given path for

```typescript
<T extends BrokerBusChannel<any>>(path: string, type?: ReceiveType<T>): Provider
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L480

### provideBusSubject (function)

Provides a bus Subject for the given channel path for

```typescript
<T extends Subject<any>>(path: string, type?: ReceiveType<T>): Provider
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L497

### isBrokerAdapterCache (function)

```typescript
(adapter: AnyAdapter): adapter is BrokerAdapterCache
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L628

### isBrokerAdapterBus (function)

```typescript
(adapter: AnyAdapter): adapter is BrokerAdapterBus
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L632

### isBrokerAdapterLock (function)

```typescript
(adapter: AnyAdapter): adapter is BrokerAdapterLock
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L636

### isBrokerAdapterQueue (function)

```typescript
(adapter: AnyAdapter): adapter is BrokerAdapterQueue
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L640

### isBrokerAdapterKeyValue (function)

```typescript
(adapter: AnyAdapter): adapter is BrokerAdapterKeyValue
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L644

### BrokerTimeOptions (type)

```typescript
interface BrokerTimeOptions {
    /**
     * Time to live in milliseconds. 0 means no ttl.
     * Value is either milliseconds or a string like '2 minutes', '8s', '24hours'.
     */
    ttl: string | number;

    /**
     * Timeout in milliseconds. 0 means no timeout.
     * Value is either milliseconds or a string like '2 minutes', '8s', '24hours'.
     */
    timeout: number | string;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L12

### BrokerTimeOptionsResolved (type)

```typescript
interface BrokerTimeOptionsResolved {
    /**
     * Time to live in milliseconds. 0 means no ttl.
     */
    ttl: number;

    /**
     * Timeout in milliseconds. 0 means no timeout.
     */
    timeout: number;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L26

### BrokerQueueMessageProcessingOptions (type)

```typescript
type BrokerQueueMessageProcessingOptions = {
    process: QueueMessageProcessing.atLeastOnce
} | {
    process: QueueMessageProcessing.exactlyOnce;
    deduplicationInterval?: string,
    hash?: string | number;
};
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L38

### BrokerQueueMessageProcessingOptionsResolved (type)

```typescript
interface BrokerQueueMessageProcessingOptionsResolved {
    process: QueueMessageProcessing;
    deduplicationInterval: number;
    hash?: string | number;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L46

### BrokerAdapterQueueProduceOptions (type)

```typescript
type BrokerAdapterQueueProduceOptions = { delay?: string; priority?: number } & BrokerQueueMessageProcessingOptions;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L52

### BrokerAdapterQueueProduceOptionsResolved (type)

```typescript
interface BrokerAdapterQueueProduceOptionsResolved extends BrokerQueueMessageProcessingOptionsResolved {
    delay?: number;
    priority?: number;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L54

### Release (type)

```typescript
type Release = () => Promise<void>;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L105

### BrokerInvalidateCacheMessage (type)

```typescript
interface BrokerInvalidateCacheMessage {
    key: string;
    ttl: number;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L107

### BrokerAdapterBase (type)

```typescript
interface BrokerAdapterBase {
    disconnect(): Promise<void>;

    logger?: Logger;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L112

### BrokerAdapterLock (type)

```typescript
interface BrokerAdapterLock extends BrokerAdapterBase {
    /**
     * Acquires the lock. If the lock is already acquired by someone else, this method waits until the lock is released.
     */
    lock(id: string, options: BrokerTimeOptionsResolved): Promise<undefined | Release>;

    /**
     * Checks if the lock is acquired by someone else.
     */
    isLocked(id: string): Promise<boolean>;

    /**
     * Tries to acquire the lock.
     * If the lock is already acquired, nothing happens.
     */
    tryLock(id: string, options: BrokerTimeOptionsResolved): Promise<undefined | Release>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L118

### BrokerAdapterBus (type)

```typescript
interface BrokerAdapterBus extends BrokerAdapterBase {
    /**
     * Publish a message on the bus aka pub/sub.
     */
    publish(name: string, message: any, type: Type): Promise<void>;

    /**
     * Subscribe to messages on the bus aka pub/sub.
     */
    subscribe(name: string, callback: (message: any) => void, type: Type): Promise<Release>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L136

### BrokerAdapterQueue (type)

```typescript
interface BrokerAdapterQueue extends BrokerAdapterBase {
    /**
     * Consume messages from a queue.
     */
    consume(name: string, callback: (message: any) => Promise<void>, options: { maxParallel: number }, type: Type): Promise<Release>;

    /**
     * Produce a message to a queue.
     */
    produce(name: string, message: any, type: Type, options?: BrokerAdapterQueueProduceOptionsResolved): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L148

### onBrokerLock (event)

```typescript
EventToken<BaseEvent>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L160

### BrokerQueueMessage (class)

```typescript
export class BrokerQueueMessage<T> {
    state:  |  | ;
    error?: Error;
    tries: number;
    delayed: number;
    constructor(public channel: string, public data: T);
    failed(error: Error);
    delay(seconds: number);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L162

### BrokerQueueChannelOptions (type)

```typescript
type BrokerQueueChannelOptions = BrokerQueueMessageProcessingOptions;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L185

### BrokerQueueChannelOptionsResolved (type)

```typescript
type BrokerQueueChannelOptionsResolved = BrokerQueueMessageProcessingOptionsResolved;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L187

### BrokerQueue (class)

```typescript
export class BrokerQueue {
    constructor(public adapter: BrokerAdapterQueue);
    channel<T>(name: string, options?: BrokerQueueChannelOptions, type?: ReceiveType<T>): BrokerQueueChannel<T>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L190

### BrokerQueueChannel (class)

```typescript
export class BrokerQueueChannel<T> {
    constructor(public name: string, private adapter: BrokerAdapterQueue, options: BrokerQueueChannelOptions | undefined, private type: Type);
    async produce<T>(message: T, options?: BrokerAdapterQueueProduceOptions): Promise<void>;
    async consume(callback: (message: BrokerQueueMessage<T>) => Promise<void> | void, options: {
        maxParallel?: number;
    } = {}): Promise<Release>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L202

### TypeOfSubject (type)

```typescript
type TypeOfSubject<T extends Subject<any>> = T extends Subject<infer U> ? U : never;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L230

### BrokerBusSubject (class)

```typescript
export class BrokerBusSubject<T> extends Subject<T> {
    constructor(public handle: BrokerBusSubjectHandle, protected onFirst: () => void, protected onLast: () => void, protected onPublish: (value: T) => void);
    override next(value: T, publish = true): void;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L232

### BusBrokerErrorHandler (class)

```typescript
export class BusBrokerErrorHandler {
    constructor(protected logger?: Logger);
    publishFailed(path: string, message: unknown, type: Type, error: Error);
    subscribeFailed(path: string, error: Error);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L383

### BrokerBus (class)

```typescript
export class BrokerBus {
    constructor(public adapter: BrokerAdapterBus, errorHandler?: BusBrokerErrorHandler);
    /**
     * Creates a broker channel handle for a given path and type.
     *
     * @param path Unique identifier of the broker channel.
     * @param type Optional message type for type-safe handling.
     */
    channel<T>(path: string, type?: ReceiveType<T>): BrokerBusChannel<T>;
    /**
     * Creates a Subject for the given broker channel.
     * Subscription to the broker is delayed until the first observer subscribes.
     *
     * Calling `.next()` publishes a message to the broker and does not forward
     * it to its observers immediately. Only messages from the broker are forwarded to observers.
     * This is to ensure consistent behaviour with other broker subjects from the same path.
     *
     * @param path Unique broker path.
     * @param type Optional type for strongly typed messages.
     *
     * @example
     * ```typescript
     * const subject = bus.subject<string>('updates');
     * subject.subscribe(console.log);
     * subject.next('hello');
     * ```
     */
    subject<T>(path: string, type?: ReceiveType<T>): Subject<T>;
    /**
     * Ensures the provided Subject is actively subscribed to the broker.
     * This guarantees that all messages from this point forward will be buffered,
     * and replayed to the first observer to avoid data loss.
     *
     * The subject unsubscribes from the broker automatically when all observers
     * are gone. To make it active, you need to subscribe to it first or call `activateSubject`.
     *
     * @throws Error when the channel could not be subscribed to.
     *
     * @example
     * ```typescript
     * const subject = bus.subject<string>('updates');
     * await bus.activateSubject(subject);
     * subject.subscribe(value => {
     *    // receives all messages from the time of activation
     * });
     * ```
     */
    async activateSubject<T extends Subject<any>>(subject: T): Promise<T>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L396

### BrokerBusChannel (class)

```typescript
export class BrokerBusChannel<T> {
    constructor(public name: string, protected adapter: BrokerAdapterBus, public type: Type);
    async publish(message: T);
    async subscribe(callback: (message: T) => void): Promise<Release>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L507

### BrokerLockError (error)

```typescript
export class BrokerLockError extends Error {
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L524

### BrokerLock (class)

```typescript
export class BrokerLock {
    constructor(public adapter: BrokerAdapterLock);
    item(id: string, options: Partial<BrokerTimeOptions> = {}): BrokerLockItem;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L528

### BrokerLockItem (class)

```typescript
export class BrokerLockItem {
    constructor(private id: string, private adapter: BrokerAdapterLock, private options: BrokerTimeOptionsResolved);
    async [Symbol.asyncDispose]();
    /**
     * Disposable way of acquiring a lock. Automatically releases the lock when the returned object is disposed.
     *
     * @example
     * ```typescript
     * async function doSomething() {
     *   async using hold = lock.hold();
     *
     *   // do stuff
     *
     *   // when out of scope, lock is automatically released.
     * }
     * ```
     */
    async hold();
    /**
     * Returns true if the current lock object is the holder of the lock.
     *
     * This does not check whether the lock is acquired by someone else.
     * Use isReserved() if you want to check that.
     */
    get acquired(): boolean;
    /**
     * Acquires the lock. If the lock is already acquired by someone else, this method waits until the lock is released.
     *
     * @throws BrokerLockError when lock is already acquired by this object.
     */
    async acquire(): Promise<this>;
    /**
     * Checks if the lock is acquired by someone else.
     */
    async isReserved(): Promise<boolean>;
    /**
     * Tries to acquire the lock.
     * If the lock is already acquired, nothing happens.
     *
     * @throws BrokerLockError when lock is already acquired by this object.
     */
    async try(): Promise<this | undefined>;
    /**
     * Releases the lock.
     */
    async release(): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L542

### BrokerAdapter (type)

```typescript
type BrokerAdapter = BrokerAdapterCache & BrokerAdapterBus & BrokerAdapterLock & BrokerAdapterQueue & BrokerAdapterKeyValue;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L625

### AnyAdapter (type)

```typescript
type AnyAdapter = BrokerAdapterCache | BrokerAdapterBus | BrokerAdapterLock | BrokerAdapterQueue | BrokerAdapterKeyValue;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker.ts#L626

### BrokerCacheOptions (type)

```typescript
interface BrokerCacheOptions {
    /**
     * Relative time to live in milliseconds. 0 means no ttl.
     *
     * Value is either milliseconds or a string like '2 minutes', '8s', '24hours'.
     */
    ttl: number | string;

    /**
     * How many ms the cache is allowed to be stale. Set to 0 to disable stale cache.
     * Default is 1000ms.
     * Improves performance by serving slightly stale cache while the cache is being rebuilt.
     */
    maxStale: number | string;

    /**
     * How many ms the cache is allowed to be stored in-memory. Set to 0 to disable in-memory cache.
     */
    inMemoryTtl: number | string;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L9

### BrokerCacheOptionsResolved (type)

```typescript
interface BrokerCacheOptionsResolved extends BrokerCacheOptions {
    ttl: number;
    maxStale: number;
    inMemoryTtl: number;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L30

### BrokerCacheItemOptions (type)

```typescript
interface BrokerCacheItemOptions {
    /**
     * Relative time to live in milliseconds. 0 means no ttl.
     *
     * Value is either milliseconds or a string like '2 minutes', '8s', '24hours'.
     */
    ttl: number | string;

    tags: string[];

    /**
     * How many ms the cache is allowed to be stale. Set to 0 to disable stale cache.
     * Default is 1000ms.
     * Improves performance by serving slightly stale cache while the cache is being rebuilt.
     */
    maxStale: number | string;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L36

### BrokerCacheItemOptionsResolved (type)

```typescript
interface BrokerCacheItemOptionsResolved extends BrokerCacheItemOptions {
    ttl: number;
    maxStale: number;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L54

### BrokerCacheError (error)

```typescript
export class BrokerCacheError extends Error {
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L75

### BrokerAdapterCache (type)

```typescript
interface BrokerAdapterCache extends BrokerAdapterBase {
    getCache(key: string, type: Type): Promise<{ value: any, ttl: number } | undefined>;

    getCacheMeta(key: string): Promise<{ ttl: number } | undefined>;

    setCache(key: string, value: any, options: BrokerCacheItemOptionsResolved, type: Type): Promise<void>;

    invalidateCache(key: string): Promise<void>;

    onInvalidateCache(callback: (key: string) => void): void;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L78

### CacheBuilder (type)

```typescript
type CacheBuilder<T> = () => T | Promise<T>;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L90

### BrokerCacheStore (class)

```typescript
export class BrokerCacheStore {
    /**
     * This is a short-lived cache pool for the current process.
     * Values are fetched from the broker when not available and stored here for a short time (configurable).
     */
    cache;
    constructor(public config: BrokerCacheOptionsResolved);
    invalidate(key: string);
    set(key: string, value: CacheStoreEntry);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L100

### BrokerCacheItem (class)

```typescript
export class BrokerCacheItem<T> {
    constructor(private key: string, private builder: CacheBuilder<T>, private options: BrokerCacheItemOptionsResolved, private adapter: BrokerAdapterCache, private store: BrokerCacheStore, private type: Type, private logger: LoggerInterface);
    async set(value: T);
    async invalidate();
    async exists(): Promise<boolean>;
    async get(): Promise<T>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L142

### BrokerCache (class)

```typescript
export class BrokerCache {
    constructor(private adapter: BrokerAdapterCache, config: Partial<BrokerCacheOptions> = {}, private logger: LoggerInterface = new ConsoleLogger());
    item<T>(key: string, builder: CacheBuilder<T>, options?: Partial<BrokerCacheItemOptions>, type?: ReceiveType<T>): BrokerCacheItem<T>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-cache.ts#L229

### parseBrokerKeyValueOptions (function)

```typescript
(options: Partial<BrokerKeyValueOptions>): BrokerKeyValueOptionsResolved
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-key-value.ts#L22

### BrokerKeyValueOptions (type)

```typescript
interface BrokerKeyValueOptions {
    /**
     * Relative time to live in milliseconds. 0 means no ttl.
     *
     * Value is either milliseconds or a string like '2 minutes', '8s', '24hours'.
     */
    ttl: number | string;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-key-value.ts#L9

### BrokerKeyValueOptionsResolved (type)

```typescript
interface BrokerKeyValueOptionsResolved extends BrokerKeyValueOptions {
    ttl: number;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-key-value.ts#L18

### BrokerAdapterKeyValue (type)

```typescript
interface BrokerAdapterKeyValue extends BrokerAdapterBase {
    get(key: string, type: Type): Promise<any>;

    set(key: string, value: any, options: BrokerKeyValueOptionsResolved, type: Type): Promise<any>;

    remove(key: string): Promise<any>;

    increment(key: string, value: number): Promise<number>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-key-value.ts#L28

### BrokerKeyValueItem (class)

```typescript
export class BrokerKeyValueItem<T> {
    constructor(private key: string, private type: Type, private adapter: BrokerAdapterKeyValue, private options: BrokerKeyValueOptionsResolved);
    /**
     * @see BrokerKeyValue.get
     */
    async get(): Promise<T>;
    /**
     * @see BrokerKeyValue.set
     */
    async set(value: T): Promise<void>;
    /**
     * @see BrokerKeyValue.increment
     */
    async increment(value: number): Promise<number>;
    async remove(): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-key-value.ts#L38

### BrokerKeyValue (class)

```typescript
export class BrokerKeyValue {
    constructor(private adapter: BrokerAdapterKeyValue, config: Partial<BrokerKeyValueOptions> = {}, private logger: LoggerInterface = new ConsoleLogger());
    /**
     * Returns a new BrokerKeyValueItem for the given key.
     */
    item<T>(key: string, options?: Partial<BrokerKeyValueOptions>, type?: ReceiveType<T>): BrokerKeyValueItem<T>;
    /**
     * Returns the value for the given key.
     */
    async get<T>(key: string, type?: ReceiveType<T>): Promise<T>;
    /**
     * Sets the value for the given key.
     */
    async set<T>(key: string, value: T, options?: Partial<BrokerKeyValueOptions>, type?: ReceiveType<T>): Promise<void>;
    async remove(key: string): Promise<void>;
    /**
     * Increments the value for the given key by the given value.
     * Note that this is not compatible to get/set, as it only works with numbers.
     * Since this an atomic increment, there is no way to get the current value via `get` and then increment it,
     * but you have to use `increment(0)` to get the current value.
     */
    async increment(key: string, value: number): Promise<number>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/broker-key-value.ts#L74

### BrokerDeepkitConnection (class)

```typescript
export class BrokerDeepkitConnection extends RpcBaseClient {
    activeChannels;
    consumers;
    subscribedToInvalidations?: ((key: string) => void)[];
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/adapters/deepkit-adapter.ts#L37

### Server (type)

```typescript
interface Server {
    url: string;
    weight?: number;
    secretKey?: string;
    transport?: ClientTransportAdapter;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/adapters/deepkit-adapter.ts#L71

### BrokerDeepkitAdapterOptions (class)

```typescript
export class BrokerDeepkitAdapterOptions {
    servers: Server[];
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/adapters/deepkit-adapter.ts#L78

### BrokerDeepkitPool (class)

```typescript
export class BrokerDeepkitPool {
    connections: {
        connection: BrokerDeepkitConnection;
        server: Server;
    }[];
    constructor(public options: BrokerDeepkitAdapterOptions);
    getConnection(key: string): BrokerDeepkitConnection;
    async disconnect(): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/adapters/deepkit-adapter.ts#L82

### BrokerDeepkitAdapter (class)

This is the Broker adapter for Deepkit Broker server.

```typescript
export class BrokerDeepkitAdapter implements BrokerAdapter {
    constructor(public options: BrokerDeepkitAdapterOptions);
    async disconnect(): Promise<void>;
    onInvalidateCache(callback: (key: string) => void): void;
    async invalidateCache(key: string): Promise<void>;
    async setCache(key: string, value: any, options: BrokerCacheItemOptionsResolved, type: Type): Promise<void>;
    async getCacheMeta(key: string): Promise<{
        ttl: number;
    } | undefined>;
    async getCache(key: string, type: Type): Promise<{
        value: any;
        ttl: number;
    } | undefined>;
    async set(key: string, value: any, options: BrokerKeyValueOptionsResolved, type: Type): Promise<void>;
    async get(key: string, type: Type): Promise<any>;
    async remove(key: string): Promise<any>;
    async increment(key: string, value: any): Promise<number>;
    async isLocked(id: string): Promise<boolean>;
    async lock(id: string, options: BrokerTimeOptionsResolved): Promise<undefined | Release>;
    async tryLock(id: string, options: BrokerTimeOptionsResolved): Promise<undefined | Release>;
    async publish(key: string, message: any, type: Type): Promise<void>;
    async subscribe(key: string, callback: (message: any) => void, type: Type): Promise<Release>;
    async produce<T>(key: string, message: T, type: Type, options?: BrokerAdapterQueueProduceOptionsResolved): Promise<void>;
    async consume(key: string, callback: (message: BrokerQueueMessage<any>) => Promise<void>, options: {
        maxParallel: number;
    }, type: Type): Promise<Release>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/adapters/deepkit-adapter.ts#L120

### BrokerMemoryAdapter (class)

In-process broker: uses the in-memory broker kernel (server)
and communicates with it via in-memory RPC transport adapter. For tests and single-process setups.

```typescript
export class BrokerMemoryAdapter extends BrokerDeepkitAdapter {
    constructor();
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/broker/src/adapters/memory-adapter.ts#L9
