This topic describes how to use SDK for Java to update the settings 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.UpdateRuleRequest;

public class updateEventRuleSample {

    private EventBridge eventBridgeClient;

    public updateEventRuleSample() {
        Config authConfig = new Config();
    authConfig.accessKeyId = "{accessKeyId}";
        authConfig.accessKeySecret = "{accessKeySecret}";
        authConfig.endpoint = "{endpoint}";
        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();
        }
    }
}