如何使用Kafka和API网关进行REST请求

huangapple go评论106阅读模式
英文:

how to make rest requests with kafka and an api gateway

问题

我是新手对于事件驱动架构,并且对于微服务通信有一个非常基本的问题。

假设我有一个需要向 API 网关发出 REST 请求的网站。比如,它执行了一个 fetch() 来请求某些资源。在事件驱动系统中,我如何获取响应或错误?

Kafka 是否接受 REST 请求并等待来自服务的特定事件消息?

英文:

I'm new to event driven architecture and have a very basic question about Microservices communication.

Given I have a website that has to make REST requests to an API Gateway. Say it does a fetch() to request some resource. How do I get a response or error in an event driven system?

Does Kafka accept rest requests and waits for a given event message from a service?

答案1

得分: 1

默认情况下,Kafka 使用 TCP。它没有 REST API 端点。

然而,例如,如果您通过 Strimzi 创建了您的 Kafka 集群,您可以通过添加 Kafka Bridge 来使用 REST API。

以下是使用 Strimzi Kafka Bridge 的示例。

如何使用Kafka和API网关进行REST请求

根据您创建 Kafka 集群的方式,您可以找到相应的方法来暴露 REST API 端点。

参考链接:https://strimzi.io/docs/bridge/latest/

英文:

By default Kafka uses TCP. It does not have REST API endpoints.

However, for example, if created your Kafka cluster by Strimzi, you can use REST API by adding Kafka Bridge.

Here is an example using Strimzi Kafka Bridge.

如何使用Kafka和API网关进行REST请求

Depending on how you created your Kafka cluster, you may find corresponding ways to expose REST API endpoints.

Reference: https://strimzi.io/docs/bridge/latest/

答案2

得分: 0

不,Kafka不接受REST请求。它使用自定义的TCP协议,而不是HTTP(S)。您可以在某个API网关后面使用Kafka REST代理来解决这个问题...

通常,您会从客户端跟踪HTTP错误,除非网关具有自己的嵌入式度量收集。

英文:

No, Kafka doesn't accept REST requests. It has a custom TCP protocol, not HTTP(S). You could use Kafka REST Proxy behind some API Gateway to solve this...

You track HTTP errors from the client, typically, unless the gateway has its own embedded metric collection.

huangapple
  • 本文由 发表于 2023年7月7日 03:46:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632116.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定