You can use event rules to filter events and route events to HTTP gateways. This topic describes the prerequisites and procedure for routing custom events to HTTP gateways. This topic also describes how to verify the result.

Step 1: Create a custom event source

  1. Log on to the EventBridge console.
  2. In the left-side navigation pane, choose Event-driven Operations > Event Sources.
  3. In the top navigation bar, select a region.
  4. On the Event Sources page, click the Custom Event Sources tab. On the Custom Event Sources tab, click Add Event Source.
  5. In the Add Custom Event Source panel, enter a name and a description, select an event provider, click Create Custom Event Bus, enter the name of a new custom event bus, and then click OK.

Step 2: Create an event rule

Notice The event targets that you want to configure for an event rule must reside in the same region as the event rule.
  1. Log on to the EventBridge console.
  2. In the left-side navigation pane, choose Event-driven Operations > Event Rules.
  3. In the top navigation bar, select a region.
  4. On the Event Rules page, select the custom event bus and click Create Rule.
  5. On the Create Rule page, perform the following steps:
    1. In the Configure Basic Info step, enter a rule name in the Name field and a rule description in the Description field, and click Next Step.
    2. In the Configure Event Pattern step, set the Event Source Type parameter to Custom Event Source, select the custom event source that is created in Step 1 from the Event Source drop-down list, specify an event pattern in the Event Pattern Content code editor, and then click Next Step.

      For more information, see Event patterns.

    3. In the Configure Targets step, configure an event target. Then, click Create.
      Note You can configure a maximum of five event targets for an event rule.
      • Service Type: Click HTTP.
      • URL: Enter a URL.
      • Body: Click Complete Event.

        For more information, see Event transformation.

      • Network Type: Select a network type.
        Valid values:
        • Internet
        • VPC

          Select a virtual private cloud (VPC), a vSwitch, and a security group.

          Notice
          • VPC is supported only in the China (Hong Kong) and China (Hangzhou) regions. The vSwitch must reside in Hongkong Zone B, Hongkong Zone C, Hangzhou Zone B, or Hangzhou Zone C. The security group must support the CIDR block of the vSwitch.
          • If you set the Network Type parameter to VPC, you can enter only an IP address but cannot enter a domain name in the URL field.

Step 3: Publish an event

  1. Log on to the EventBridge console.
  2. In the left-side navigation pane, choose Event-driven Operations > Event Buses.
  3. In the top navigation bar, select a region.
  4. In the Custom Event Buses section, find the event bus to which you want to publish an event and click Publish Event in the Operations column.
    Note You can publish events only to custom event buses in the EventBridge console.
  5. In the Publish Event to Custom Event Bus panel, enter the event content in the code editor and click OK.
    For more information about the event parameters, see Overview.

Verify the result

You can use an HTTP gateway to receive the event and view the event content. The following code provides an example on how to use an HTTP gateway to receive the event:

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@SpringBootApplication
@Slf4j
public class EventProcessingApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @PostMapping("/eventBridge/processEvent")
    @ResponseBody
    public String revieveMessage(@RequestBody String data) {
        log.info("revieveEvent");
        log.info(data);
        return "recieved";
    }
}