This topic describes how to use SDK for Java to create an event bus.

Sample code:

import com.aliyun.eventbridge.EventBridge;
import com.aliyun.eventbridge.EventBridgeClient;
import com.aliyun.eventbridge.models.Config;
import com.aliyun.eventbridge.models.CreateEventBusRequest;
import com.aliyun.eventbridge.models.CreateEventBusResponse;

public class createEventBusSample {

    private EventBridge eventBridgeClient;

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

    public void createEventBusSample() {
        try {
            CreateEventBusRequest createEventBusRequest = new CreateEventBusRequest();
            createEventBusRequest.setEventBusName("mybus");
            createEventBusRequest.setDescription("my first bus on eventbridge!") ;
            CreateEventBusResponse response = eventBridgeClient.createEventBus(createEventBusRequest);
            System.out.println("create bus success : " + response);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }


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