Can spring request reply can be implemented with client side using spring kafka API's and server side using apache kafka API?

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

Can spring request reply can be implemented with client side using spring kafka API's and server side using apache kafka API?

问题

可以使用Spring Kafka API在客户端实现Spring请求回复,同时使用Apache Kafka API在服务器端实现吗?

英文:

Can spring request reply can be implemented with client side using spring kafka API's and server side using apache kafka API ?

答案1

得分: 0

Spring for Apache Kafka提供了使用ReplyingKafkaTemplate和带有@KafkaListener@SendTo来实现请求/回复。

文档在这里

编辑

当使用多个客户端实例时...

>如果您有多个客户端实例,并且您没有按照前面的段落所讨论的那样对它们进行配置,则每个实例都需要一个专用的回复主题。另一种选择是设置KafkaHeaders.REPLY_PARTITION并为每个实例使用专用分区。标头包含一个四字节的整数(大端序)。服务器必须使用此标头将回复路由到正确的分区(@KafkaListener会执行此操作)。不过,在这种情况下,回复容器不能使用Kafka的组管理功能,并且必须配置为在固定分区上进行侦听(通过在其ContainerProperties构造函数中使用TopicPartitionOffset)。

>当配置单个回复主题时,每个实例必须使用不同的group.id。在这种情况下,所有实例都会收到每个回复,但只有发送请求的实例才会找到关联ID。这对于自动扩展可能是有用的,但会增加额外的网络流量成本,并且需要付出丢弃每个不需要的回复的小成本。在使用此设置时,我们建议将模板的sharedReplyTopic设置为true,以便将意外回复的日志级别从默认的ERROR降低为DEBUG

英文:

Spring for Apache Kafka provides request/reply using the ReplyingKafkaTemplate and @KafkaListener with a @SendTo.

Documentation here.

EDIT

When using multiple client instances...

>f you have multiple client instances and you do not configure them as discussed in the preceding paragraph, each instance needs a dedicated reply topic. An alternative is to set the KafkaHeaders.REPLY_PARTITION and use a dedicated partition for each instance. The Header contains a four-byte int (big-endian). The server must use this header to route the reply to the correct partition (@KafkaListener does this). In this case, though, the reply container must not use Kafka’s group management feature and must be configured to listen on a fixed partition (by using a TopicPartitionOffset in its ContainerProperties constructor).

>When configuring with a single reply topic, each instance must use a different group.id. In this case, all instances receive each reply, but only the instance that sent the request finds the correlation ID. This may be useful for auto-scaling, but with the overhead of additional network traffic and the small cost of discarding each unwanted reply. When you use this setting, we recommend that you set the template’s sharedReplyTopic to true, which reduces the logging level of unexpected replies to DEBUG instead of the default ERROR.

huangapple
  • 本文由 发表于 2020年9月14日 21:42:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63885558.html
匿名

发表评论

匿名网友

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

确定