Skip to Content
微服务与事件驱动架构
book

微服务与事件驱动架构

by Adam Bellemare
October 2021
Beginner to intermediate
250 pages
7h 11m
Chinese
Posts & Telecom Press
Content preview from 微服务与事件驱动架构
170
13
根据
schema
和事件定义将传入事件分类到它们自己定义的事件流中是很重要的。根据业
务目标分离这些事件,就像分离任何其他微服务的事件流一样。
13.3
 集成第三方
请求
响应
API
事件驱动型微服务经常需要通过“请求
响应”协议与第三方
API
通信。“请求
响应”
模式能够很好地适配事件驱动型处理,请求和响应被简单地视为远程函数调用。微服务基
于事件驱动的逻辑调用
API
等待回复。在收到回复后,微服务将对其进行解析,确保其
符合预期的
schema
,并继续应用业务逻辑
,就像处理任何其他事件一样。图
13-3
展示了
这种处理的一个例子。
输入事件流
结果事件流
消费+请求
响应解析器
业务逻辑
生产者
微服务
外部“请求
响应”端点
1) 消费事件
2) 发起请求
3) 接收响应
4) 解析响应并
引用业务逻辑
5) 生成输出事件
13-3:集成“请求 响应”API 到事件驱动的工作流中
以下源代码展示了使用阻塞式调用的微服务的逻辑操作。
while (true) { //无限循环处理
Event[] eventsToProcess = Consumer.consume("input-event-stream");
for (Event event: eventsToProcess) {
//对当前事件应用业务逻辑以生成必要的请求
Request request = generateRequest(event, ...);
//向外部端点发起请求。指定了超时、重试等参数值
//这段代码使用阻塞式调用来等待一个响应 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

监控运维实践:原则与策略

监控运维实践:原则与策略

Mike Julian
Kafka权威指南

Kafka权威指南

Neha Narkhede, Gwen Shapira, Todd Palino
Web容量规划之美

Web容量规划之美

Arun Kejariwal, John Allspaw

Publisher Resources

ISBN: 9787115571106