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

Sample code:

import com.aliyun.eventbridge.EventBridge;
import com.aliyun.eventbridge.EventBridgeClient;
import com.aliyun.eventbridge.models.Config;
import com.aliyun.eventbridge.models.ListTargetsRequest;
import com.aliyun.eventbridge.models.ListTargetsResponse;

public class listTargetsSample {

    private EventBridge eventBridgeClient;

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

    public void listTargetsSample() {
        try {
            ListTargetsRequest listTargetsRequest = new ListTargetsRequest();
            listTargetsRequest.setRuleName("myRule");
            listTargetsRequest.setEventBusName("mybus");
            ListTargetsResponse response = eventBridgeClient.listTargets(listTargetsRequest);
            System.out.println("list targets success : " + response);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

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