【发布时间】:2021-03-11 19:56:12
【问题描述】:
我在微服务方面没有太多经验,不太了解如何进行 在下述情况下。 我有两个 Web 服务,一个生产者和一个消费者。它们通过 Apache Kafka 进行通信,生产者自己周期性地抛出带有随机 id 和分数的消息,消费者计算并存储 Map 中每个 id 的平均分数。
所以,我需要实现一个 REST API 端点,当提供一个 id 时,它会返回对应于这个 id 的平均分数。实际上,我在消费者控制器中为这个需求(GET请求)做了一个常用的方法。我检查了邮递员,它运作良好。 但是当一个组中有很多消费者实例,而不仅仅是一个时,在这种情况下客户端不知道将请求发送到哪个端口呢?毕竟,每个实例都是在操作系统选择的端口(server.port = 0)上启动的。在这种情况下,为了让一切正常运行,我需要添加一些额外的服务,或者我可以通过其他方式在没有它们的情况下做某事吗?
Just in case, I am adding the application.properties files if somebody needed for the answer:
Producer:
spring.cloud.stream.bindings.output.destination=customers
spring.cloud.stream.bindings.output.producer.partitionKeyExpression=payload.id
spring.cloud.stream.bindings.output.producer.partitionCount=10
Consumer:
spring.cloud.stream.bindings.input.destination=customers
spring.cloud.stream.bindings.input.group=customer_group
spring.cloud.stream.instanceCount=10
server.port=0
【问题讨论】:
标签: spring api rest microservices