This topic describes how to use SDK for Java to query all the event rules of an event bus.

Sample code:

import com.aliyun.eventbridge.EventBridge;
import com.aliyun.eventbridge.EventBridgeClient;
import com.aliyun.eventbridge.models.Config;
import com.aliyun.eventbridge.models.ListRulesRequest;
import com.aliyun.eventbridge.models.ListRulesResponse;

public class listEventRuleSample {

    private EventBridge eventBridgeClient;

    public listEventRuleSample() {
        Config authConfig = new Config();
    authConfig.accessKeyId = "{accessKeyId}";
        authConfig.accessKeySecret = "{accessKeySecret}";
        authConfig.endpoint = "{endpoint}";
        eventBridgeClient = new EventBridgeClient(authConfig);
    }

    public void listEventRuleSample() {
        try {
            ListRulesRequest listEventRulesRequest = new ListRulesRequest();
            listEventRulesRequest.setEventBusName("mybus");
            ListRulesResponse response = eventBridgeClient.listRules(listEventRulesRequest);
            System.out.println("list rule success : " + response);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        listEventRuleSample eventRuleSamples = new listEventRuleSample();
        try {
            eventRuleSamples.listEventRuleSample();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}