本文介绍如何使用Java SDK更新一个事件规则的配置。

示例代码如下:

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

public class updateEventRuleSample {

    private EventBridge eventBridgeClient;

    public updateEventRuleSample() {
        Config authConfig = new Config();
    authConfig.accessKeyId = "{accessKeyId}";// AccessKey ID,阿里云身份验证,在RAM控制台创建。获取方式,请参见获取AccessKey。
        authConfig.accessKeySecret = "{accessKeySecret}";// AccessKey Secret,阿里云身份验证,在RAM控制台创建。获取方式,请参见获取AccessKey。
        authConfig.endpoint = "{endpoint}";// 接入点信息。具体信息,请参见地域和接入点。
        eventBridgeClient = new EventBridgeClient(authConfig);
        eventBridgeClient = new EventBridgeClient(authConfig);
    }

    public void updateEventRuleSample() {
        try {
            UpdateRuleRequest updateEventRuleRequest = new UpdateRuleRequest();
            updateEventRuleRequest.setRuleName("myRule");
            updateEventRuleRequest.setEventBusName("mybus");
            updateEventRuleRequest.setFilterPattern("{\"source\":[\"crmabc.newsletter\"],\"type\":[\"UserSignUp\"]}");
            eventBridgeClient.updateRule(updateEventRuleRequest);
            System.out.println("update rule success! ");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

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