Skip to content

@codesoul-co/hypha-core / modules/runtime/message-inbox-outbox

模块用法

用于执行该边界的运行时行为。Message inbox outbox 模块公开 4 类、8 接口。

从包入口导入

ts
import {
  InMemoryRuntimeMessageInboxStore,
  InMemoryRuntimeMessageOutboxStore,
  RuntimeInboxProcessor,
  RuntimeOutboxDispatcher,
} from '@codesoul-co/hypha-core';

import type {
  InboxClaimRequest,
  InboxClaimResult,
  RuntimeInboxHandleResult,
  RuntimeInboxProcessorOptions,
  RuntimeMessageInboxStore,
  RuntimeMessageOutboxStore,
  RuntimeOutboxDispatcherOptions,
  RuntimeOutboxDispatchResult,
} from '@codesoul-co/hypha-core';

使用要点

  • 8 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 4 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。

公共导出

Symbol种类签名说明
InMemoryRuntimeMessageInboxStorenew InMemoryRuntimeMessageInboxStore(): InMemoryRuntimeMessageInboxStoreIn Memory Runtime Message Inbox Store 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。
InMemoryRuntimeMessageOutboxStorenew InMemoryRuntimeMessageOutboxStore(): InMemoryRuntimeMessageOutboxStoreIn Memory Runtime Message Outbox Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。
RuntimeInboxProcessornew RuntimeInboxProcessor(options: RuntimeInboxProcessorOptions): RuntimeInboxProcessorRuntime Inbox Processor 类,共公开 2 个构造函数或成员;精确签名见本条目的声明与成员表。
RuntimeOutboxDispatchernew RuntimeOutboxDispatcher(options: RuntimeOutboxDispatcherOptions): RuntimeOutboxDispatcherRuntime Outbox Dispatcher 类,共公开 2 个构造函数或成员;精确签名见本条目的声明与成员表。
InboxClaimRequest接口interface InboxClaimRequestInbox Claim Request 接口,共包含 7 个公开字段或方法。
InboxClaimResult接口interface InboxClaimResultInbox Claim Result 接口,共包含 2 个公开字段或方法。
RuntimeInboxHandleResult接口interface RuntimeInboxHandleResultRuntime Inbox Handle Result 接口,共包含 3 个公开字段或方法。
RuntimeInboxProcessorOptions接口interface RuntimeInboxProcessorOptionsRuntime Inbox Processor Options 接口,共包含 5 个公开字段或方法。
RuntimeMessageInboxStore接口interface RuntimeMessageInboxStoreRuntime Message Inbox Store 接口,共包含 5 个公开字段或方法。
RuntimeMessageOutboxStore接口interface RuntimeMessageOutboxStoreRuntime Message Outbox Store 接口,共包含 6 个公开字段或方法。
RuntimeOutboxDispatcherOptions接口interface RuntimeOutboxDispatcherOptionsRuntime Outbox Dispatcher Options 接口,共包含 7 个公开字段或方法。
RuntimeOutboxDispatchResult接口interface RuntimeOutboxDispatchResultRuntime Outbox Dispatch Result 接口,共包含 4 个公开字段或方法。

InMemoryRuntimeMessageInboxStore

In Memory Runtime Message Inbox Store 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。

声明

text
export declare class InMemoryRuntimeMessageInboxStore implements RuntimeMessageInboxStore {
    claim(request: InboxClaimRequest): Promise<InboxClaimResult>;
    complete(consumerId: string, messageId: string, ownerId: string, appliedEventIds: string[], completedAt: string): Promise<void>;
    fail(consumerId: string, messageId: string, ownerId: string, error: NormalizedRuntimeError, failedAt: string): Promise<void>;
    get(consumerId: string, messageId: string): Promise<RuntimeMessageInboxRecord | null>;
    health(): Promise<ProviderHealth>;
}

公开成员

成员种类签名说明
claim方法claim(request: InboxClaimRequest): Promise<InboxClaimResult>公开方法;参数与返回类型以签名列为准。
complete方法complete(consumerId: string, messageId: string, ownerId: string, appliedEventIds: string[], completedAt: string): Promise<void>公开方法;参数与返回类型以签名列为准。
constructor构造函数(): InMemoryRuntimeMessageInboxStore创建该类的实例。
fail方法fail(consumerId: string, messageId: string, ownerId: string, error: NormalizedRuntimeError, failedAt: string): Promise<void>公开方法;参数与返回类型以签名列为准。
get方法get(consumerId: string, messageId: string): Promise<RuntimeMessageInboxRecord | null>公开方法;参数与返回类型以签名列为准。
health方法health(): Promise<ProviderHealth>公开方法;参数与返回类型以签名列为准。

InMemoryRuntimeMessageOutboxStore

In Memory Runtime Message Outbox Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。

声明

text
export declare class InMemoryRuntimeMessageOutboxStore implements RuntimeMessageOutboxStore {
    enqueue(input: {
            id: string;
            eventId?: string;
            envelope: RuntimeMessageEnvelope;
            availableAt?: string;
            createdAt: string;
        }): Promise<RuntimeMessageOutboxRecord>;
    claim(input: {
            ownerId: string;
            now: string;
            leaseMs: number;
            limit: number;
        }): Promise<RuntimeMessageOutboxRecord[]>;
    markPublished(id: string, ownerId: string, publishedAt: string): Promise<void>;
    markFailed(input: {
            id: string;
            ownerId: string;
            failedAt: string;
            error: NormalizedRuntimeError;
            retryAt?: string;
            deadLetter?: boolean;
        }): Promise<void>;
    get(id: string): Promise<RuntimeMessageOutboxRecord | null>;
    health(): Promise<ProviderHealth>;
}

公开成员

成员种类签名说明
claim方法claim(input: { ownerId: string; now: string; leaseMs: number; limit: number; }): Promise<RuntimeMessageOutboxRecord[]>公开方法;参数与返回类型以签名列为准。
constructor构造函数(): InMemoryRuntimeMessageOutboxStore创建该类的实例。
enqueue方法enqueue(input: { id: string; eventId?: string; envelope: RuntimeMessageEnvelope; availableAt?: string; createdAt: string; }): Promise<RuntimeMessageOutboxRecord>公开方法;参数与返回类型以签名列为准。
get方法get(id: string): Promise<RuntimeMessageOutboxRecord | null>公开方法;参数与返回类型以签名列为准。
health方法health(): Promise<ProviderHealth>公开方法;参数与返回类型以签名列为准。
markFailed方法markFailed(input: { id: string; ownerId: string; failedAt: string; error: NormalizedRuntimeError; retryAt?: string; deadLetter?: boolean; }): Promise<void>公开方法;参数与返回类型以签名列为准。
markPublished方法markPublished(id: string, ownerId: string, publishedAt: string): Promise<void>公开方法;参数与返回类型以签名列为准。

RuntimeInboxProcessor

Runtime Inbox Processor 类,共公开 2 个构造函数或成员;精确签名见本条目的声明与成员表。

声明

text
export declare class RuntimeInboxProcessor {
    constructor(options: RuntimeInboxProcessorOptions);
    handle(delivery: MessageDelivery, apply: (envelope: RuntimeMessageEnvelope) => Promise<string[]>): Promise<RuntimeInboxHandleResult>;
}

公开成员

成员种类签名说明
constructor构造函数(options: RuntimeInboxProcessorOptions): RuntimeInboxProcessor创建该类的实例。
handle方法handle(delivery: MessageDelivery, apply: (envelope: RuntimeMessageEnvelope) => Promise<string[]>): Promise<RuntimeInboxHandleResult>公开方法;参数与返回类型以签名列为准。

RuntimeOutboxDispatcher

Runtime Outbox Dispatcher 类,共公开 2 个构造函数或成员;精确签名见本条目的声明与成员表。

声明

text
export declare class RuntimeOutboxDispatcher {
    constructor(options: RuntimeOutboxDispatcherOptions);
    dispatch(limit?: number): Promise<RuntimeOutboxDispatchResult>;
}

公开成员

成员种类签名说明
constructor构造函数(options: RuntimeOutboxDispatcherOptions): RuntimeOutboxDispatcher创建该类的实例。
dispatch方法dispatch(limit?: number): Promise<RuntimeOutboxDispatchResult>公开方法;参数与返回类型以签名列为准。

InboxClaimRequest

Inbox Claim Request 接口,共包含 7 个公开字段或方法。

声明

text
export interface InboxClaimRequest {
    consumerId: string;
    ownerId: string;
    messageId: string;
    payloadHash: string;
    receivedAt: string;
    processingLeaseMs: number;
    expiresAt?: string;
}

契约成员

成员种类签名说明
consumerId属性consumerId: string公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
messageId属性messageId: string公开属性;类型、只读和可选状态以签名列为准。
ownerId属性ownerId: string公开属性;类型、只读和可选状态以签名列为准。
payloadHash属性payloadHash: string公开属性;类型、只读和可选状态以签名列为准。
processingLeaseMs属性processingLeaseMs: number公开属性;类型、只读和可选状态以签名列为准。
receivedAt属性receivedAt: string公开属性;类型、只读和可选状态以签名列为准。

InboxClaimResult

Inbox Claim Result 接口,共包含 2 个公开字段或方法。

声明

text
export interface InboxClaimResult {
    disposition: 'claimed' | 'duplicate' | 'busy' | 'conflict' | 'expired';
    record: RuntimeMessageInboxRecord;
}

契约成员

成员种类签名说明
disposition属性disposition: "busy" | "expired" | "claimed" | "conflict" | "duplicate"公开属性;类型、只读和可选状态以签名列为准。
record属性record: RuntimeMessageInboxRecord公开属性;类型、只读和可选状态以签名列为准。

RuntimeInboxHandleResult

Runtime Inbox Handle Result 接口,共包含 3 个公开字段或方法。

声明

text
export interface RuntimeInboxHandleResult {
    disposition: 'applied' | 'duplicate' | 'busy' | 'failed' | 'dead_lettered' | 'expired';
    appliedEventIds: string[];
    ackPending?: boolean;
}

契约成员

成员种类签名说明
ackPending属性ackPending?: boolean公开属性;类型、只读和可选状态以签名列为准。
appliedEventIds属性appliedEventIds: string[]公开属性;类型、只读和可选状态以签名列为准。
disposition属性disposition: "failed" | "busy" | "expired" | "applied" | "dead_lettered" | "duplicate"公开属性;类型、只读和可选状态以签名列为准。

RuntimeInboxProcessorOptions

Runtime Inbox Processor Options 接口,共包含 5 个公开字段或方法。

声明

text
export interface RuntimeInboxProcessorOptions {
    consumerId: string;
    ownerId: string;
    inbox: RuntimeMessageInboxStore;
    now?: () => string;
    processingLeaseMs?: number;
}

契约成员

成员种类签名说明
consumerId属性consumerId: string公开属性;类型、只读和可选状态以签名列为准。
inbox属性inbox: RuntimeMessageInboxStore公开属性;类型、只读和可选状态以签名列为准。
now方法now?(): string公开方法;参数与返回类型以签名列为准。
ownerId属性ownerId: string公开属性;类型、只读和可选状态以签名列为准。
processingLeaseMs属性processingLeaseMs?: number公开属性;类型、只读和可选状态以签名列为准。

RuntimeMessageInboxStore

Runtime Message Inbox Store 接口,共包含 5 个公开字段或方法。

声明

text
export interface RuntimeMessageInboxStore {
    claim(request: InboxClaimRequest): Promise<InboxClaimResult>;
    complete(consumerId: string, messageId: string, ownerId: string, appliedEventIds: string[], completedAt: string): Promise<void>;
    fail(consumerId: string, messageId: string, ownerId: string, error: NormalizedRuntimeError, failedAt: string): Promise<void>;
    get(consumerId: string, messageId: string): Promise<RuntimeMessageInboxRecord | null>;
    health(): Promise<ProviderHealth>;
}

契约成员

成员种类签名说明
claim方法claim(request: InboxClaimRequest): Promise<InboxClaimResult>公开方法;参数与返回类型以签名列为准。
complete方法complete(consumerId: string, messageId: string, ownerId: string, appliedEventIds: string[], completedAt: string): Promise<void>公开方法;参数与返回类型以签名列为准。
fail方法fail(consumerId: string, messageId: string, ownerId: string, error: NormalizedRuntimeError, failedAt: string): Promise<void>公开方法;参数与返回类型以签名列为准。
get方法get(consumerId: string, messageId: string): Promise<RuntimeMessageInboxRecord | null>公开方法;参数与返回类型以签名列为准。
health方法health(): Promise<ProviderHealth>公开方法;参数与返回类型以签名列为准。

RuntimeMessageOutboxStore

Runtime Message Outbox Store 接口,共包含 6 个公开字段或方法。

声明

text
export interface RuntimeMessageOutboxStore {
    enqueue(input: {
        id: string;
        eventId?: string;
        envelope: RuntimeMessageEnvelope;
        availableAt?: string;
        createdAt: string;
    }): Promise<RuntimeMessageOutboxRecord>;
    claim(input: {
        ownerId: string;
        now: string;
        leaseMs: number;
        limit: number;
    }): Promise<RuntimeMessageOutboxRecord[]>;
    markPublished(id: string, ownerId: string, publishedAt: string): Promise<void>;
    markFailed(input: {
        id: string;
        ownerId: string;
        failedAt: string;
        error: NormalizedRuntimeError;
        retryAt?: string;
        deadLetter?: boolean;
    }): Promise<void>;
    get(id: string): Promise<RuntimeMessageOutboxRecord | null>;
    health(): Promise<ProviderHealth>;
}

契约成员

成员种类签名说明
claim方法claim(input: { ownerId: string; now: string; leaseMs: number; limit: number; }): Promise<RuntimeMessageOutboxRecord[]>公开方法;参数与返回类型以签名列为准。
enqueue方法enqueue(input: { id: string; eventId?: string; envelope: RuntimeMessageEnvelope; availableAt?: string; createdAt: string; }): Promise<RuntimeMessageOutboxRecord>公开方法;参数与返回类型以签名列为准。
get方法get(id: string): Promise<RuntimeMessageOutboxRecord | null>公开方法;参数与返回类型以签名列为准。
health方法health(): Promise<ProviderHealth>公开方法;参数与返回类型以签名列为准。
markFailed方法markFailed(input: { id: string; ownerId: string; failedAt: string; error: NormalizedRuntimeError; retryAt?: string; deadLetter?: boolean; }): Promise<void>公开方法;参数与返回类型以签名列为准。
markPublished方法markPublished(id: string, ownerId: string, publishedAt: string): Promise<void>公开方法;参数与返回类型以签名列为准。

RuntimeOutboxDispatcherOptions

Runtime Outbox Dispatcher Options 接口,共包含 7 个公开字段或方法。

声明

text
export interface RuntimeOutboxDispatcherOptions {
    ownerId: string;
    outbox: RuntimeMessageOutboxStore;
    bus: MessageBus;
    now?: () => string;
    leaseMs?: number;
    maxAttempts?: number;
    retryDelayMs?: (attempt: number) => number;
}

契约成员

成员种类签名说明
bus属性bus: MessageBus公开属性;类型、只读和可选状态以签名列为准。
leaseMs属性leaseMs?: number公开属性;类型、只读和可选状态以签名列为准。
maxAttempts属性maxAttempts?: number公开属性;类型、只读和可选状态以签名列为准。
now方法now?(): string公开方法;参数与返回类型以签名列为准。
outbox属性outbox: RuntimeMessageOutboxStore公开属性;类型、只读和可选状态以签名列为准。
ownerId属性ownerId: string公开属性;类型、只读和可选状态以签名列为准。
retryDelayMs方法retryDelayMs?(attempt: number): number公开方法;参数与返回类型以签名列为准。

RuntimeOutboxDispatchResult

Runtime Outbox Dispatch Result 接口,共包含 4 个公开字段或方法。

声明

text
export interface RuntimeOutboxDispatchResult {
    claimed: number;
    published: number;
    failed: number;
    deadLettered: number;
}

契约成员

成员种类签名说明
claimed属性claimed: number公开属性;类型、只读和可选状态以签名列为准。
deadLettered属性deadLettered: number公开属性;类型、只读和可选状态以签名列为准。
failed属性failed: number公开属性;类型、只读和可选状态以签名列为准。
published属性published: number公开属性;类型、只读和可选状态以签名列为准。