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

public class enableEventRuleSample {

    private EventBridge eventBridgeClient;

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

    public void enableEventRuleSample() {
        try {
            EnableRuleRequest enableEventRuleRequest = new EnableRuleRequest();
            enableEventRuleRequest.setRuleName("myRule");
            enableEventRuleRequest.setEventBusName("mybus");
            eventBridgeClient.enableRule(enableEventRuleRequest);
            System.out.println("enable rule success : " + enableEventRuleRequest.getEventBusName() + "/"
                    + enableEventRuleRequest.getRuleName());
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

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