本文介绍如何使用TypeScript SDK查询一个事件总线下的所有事件规则。

示例代码如下:

import EventBridge, * as $EventBridge from '@alicloud/eventbridge';
import Util from '@alicloud/tea-util';
import Console from '@alicloud/tea-console';
import * as $tea from '@alicloud/tea-typescript';

export default class Client {

    /**
     * Create client初始化公共请求参数。
     */
    static async createClient(): Promise<EventBridge> {
        let config = new $EventBridge.Config({ });
        // 您的AccessKey ID。
        config.accessKeyId = "<accessKeyId>";
        // 您的AccessKey Secret。
        config.accessKeySecret = "<accessKeySecret>";
        // 您的接入点。
        config.endpoint = "<endpoint>";
        return new EventBridge(config);
    }

    static async listEventRulesSample(client: EventBridge): Promise<void> {
        try {
            let listEventRulesRequest = new $EventBridge.ListRulesRequest({ });
            listEventRulesRequest.eventBusName = "demo-bus";
            let resp = await client.listRules(listEventRulesRequest);
            Console.log("--------------------list rule success--------------------");
            Console.log(Util.toJSONString($tea.toMap(resp)));
        } catch (error) {
            Console.log(error.message);
        }
    }

    static async main(args: string[]): Promise<void> {
        let client = await Client.createClient();
        await Client.listEventRulesSample(client);
    }

}

Client.main(process.argv.slice(2));