FolkMQ v1.7.8

客户端接口

直接放代码了,省事儿。还可以看注释。以下用 TypeScript 表示:

FolkMQ

export class FolkMQ {
    /**
     * 获取版本代号(用于控制元信息版本)
     */
    static versionCode(): number;
     /**
     * 获取版本代号字符串形式
     */
    static versionCodeAsString(): string;
    /**
     * 获取版本
     */
    static versionName(): string;
    /**
     * 创建客户端
     */
    static createClient(serverUrls: string[] | string): MqClient;
    /**
     * 新建路由
     * */
    static newRouter(mappingHandler: IoFunction<MqMessageReceived, string>): MqRouter;
    /**
     * 新建消息
     * */
    static newMessage(content: string): MqMessage;
    /**
     * 新建告警
     * */
    static newAlarm(content: string): MqAlarm;
    /**
     * 新建实体
     * */
    static newEntity(data?: String | Blob | ArrayBuffer): Entity;
}

MqClient

/**
 * 消息客户端
 */
export interface MqClient {
    /**
     * 名字
     */
    name(): string;

    /**
     * 名字取为
     */
    nameAs(name: string): MqClient;

    /**
     * 连接
     */
    connect(): Promise<MqClient>;

    /**
     * 断开连接
     */
    disconnect();

    /**
     * 客户端配置
     */
    config(configHandler: IoConsumer<ClientConfig>): MqClient;

    /**
     * 自动回执
     *
     * @param auto 自动(默认为 true)
     */
    autoAcknowledge(auto: boolean): MqClient;

    /**
     * 订阅主题
     *
     * @param topic           主题
     * @param consumerGroup   消费者组
     * @param consumerHandler 消费处理
     */
    subscribe(topic: string, consumerGroup: string | null, autoAck: boolean | null, consumerHandler: IoConsumer<MqMessageReceived>);

    /**
     * 取消订阅主题
     *
     * @param topic         主题
     * @param consumerGroup 消费者组
     */
    unsubscribe(topic: string, consumerGroup: string | null);

    /**
     * 同步发布消息
     *
     * @param topic   主题
     * @param message 消息
     */
    publish(topic: string, message: MqMessage);

    /**
     * 取消发布
     *
     * @param topic 主题
     * @param tid   跟踪id
     */
    unpublish(topic: string, tid: string);

    /**
     * 监听
     *
     * @param listenHandler 监听处理
     */
    listen(listenHandler: IoConsumer<MqMessageReceived>);

    /**
     * 发送
     *
     * @param message 消息
     * @param toName  发送目标名字
     * @param timeout 超时(单位毫秒)
     */
    send(message: MqMessage, toName: string, timeout?: number): RequestStream | null;

    /**
     * 事务回查
     *
     * @param transactionCheckback 事务回查处理
     */
    transactionCheckback(transactionCheckback: IoConsumer<MqMessageReceived>);

    /**
     * 新建事务
     */
    newTransaction(): MqTransaction;
}