两个同步客户端可以使用相同的 request/reply 主题吗

Can two synchronous clients use same request/reply topic

我有一个用户服务正在侦听请求主题并返回用户对象。我需要从两个不同的服务同步调用此服务,并想确认它们是否可以使用相同的 request/response 主题名称来同时请求用户对象?

如果多个消费者属于不同的消费者组,则多个消费者可以读取和处理来自同一主题的相同消息。

参见 the documentation

同一个回复主题有两种选择:

  1. 丢弃意外回复:

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.

  1. 使用专用分区:

If 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).