本文介绍如何使用Java SDK删除一个事件规则。

示例代码如下:

import com.aliyun.eventbridge.EventBridge;
import com.aliyun.eventbridge.EventBridgeClient;
import com.aliyun.eventbridge.models.Config;
import com.aliyun.eventbridge.models.DeleteRuleRequest;

public class deleteEventRuleSample {

    private EventBridge eventBridgeClient;

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

    public void deleteEventRuleSample() {
        try {
            DeleteRuleRequest deleteEventRuleRequest = new DeleteRuleRequest();
            deleteEventRuleRequest.setRuleName("myRule");
            deleteEventRuleRequest.setEventBusName("mybus");
            eventBridgeClient.deleteRule(deleteEventRuleRequest);
            System.out.println("delete rule success : " + deleteEventRuleRequest.getEventBusName() + "/"
                    + deleteEventRuleRequest.getRuleName());
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

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