您可以通过事件规则过滤事件,将事件路由到HTTP端点地址。本文以自定义事件为例介绍将事件路由到HTTP端点地址的前提条件、操作步骤和结果验证。
前提条件
步骤一:添加自定义事件源
- 登录事件总线EventBridge控制台,在左侧导航栏,单击事件总线。
- 在顶部菜单栏,选择地域,在事件总线页面,单击目标自定义事件总线名称。
- 在左侧导航栏,单击事件源,然后单击添加事件源。
- 在添加自定义事件源面板,输入名称和描述,事件提供方选择自定义应用,然后单击确定。
步骤二:创建事件规则
重要 目标服务和事件规则必须处于同一地域。
- 登录事件总线EventBridge控制台,在左侧导航栏,单击事件总线。
- 在顶部菜单栏,选择地域,在事件总线页面,单击目标总线名称。
- 在左侧导航栏,单击事件规则,然后单击创建规则。
- 在创建规则页面,完成以下操作。
步骤三:发布事件
结果验证
您可以通过HTTP网关接收事件查看事件内容。代码示例如下所示。
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 receiveMessage(@RequestBody String data) {
log.info("receiveEvent");
log.info(data);
return "received";
}
}