You can use event rules to filter events and route events to HTTP endpoints. This topic describes the prerequisites and procedure for routing custom events to HTTP endpoints. This topic also describes how to verify the result.
Prerequisites
Step 1: Create a custom event source
- Log on to the EventBridge console.
- In the left-side navigation pane, click Event Buses.
- In the top navigation bar, select a region.
- On the Event Buses page, click the name of the target event bus.
- In the left-side navigation pane, click Event Sources.
- On the Event Sources page, click Add Event Source.
- In the Add Custom Event Source panel, set the Name and Description parameters, select Custom Application from the Event Provider drop-down list, 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.
- Log on to the EventBridge console.
- In the left-side navigation pane, click Event Buses.
- In the top navigation bar, select a region.
- On the Event Buses page, click the name of the target event bus.
- In the left-side navigation pane, click Event Rules.
- On the Event Rules page, click Create Rule.
- Complete the Create Rule wizard.
Step 3: Publish an event
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";
}
}