This topic describes how to use SDK for Java to disable 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.DisableRuleRequest;

public class disableEventRuleSample {

    private EventBridge eventBridgeClient;

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

    public void disableEventRuleSample() {
        try {
            DisableRuleRequest disableEventRuleRequest = new DisableRuleRequest();
            disableEventRuleRequest.setRuleName("myRule");
            disableEventRuleRequest.setEventBusName("mybus");
            eventBridgeClient.disableRule(disableEventRuleRequest);
            System.out.println("disable rule success : " + disableEventRuleRequest.getEventBusName() + "/"
                    + disableEventRuleRequest.getRuleName());
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

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