Reputation: 61
I do not have a lot of experience in microservices and do not quite understand how to proceed in the situation described below. I have two web services, a producer and a consumer. They communicate through Apache Kafka, the producer itself periodically throws messages with random id and score, and the consumer calculates and stores the average score for each id in the Map.
So, I need to implement a REST API endpoint, which, when provided with an id, returns the average score which corresponds to this id. Actually, I made a usual method in the consumer controller for this need (GET request). I checked on Postman, it works well. But what about when there are many consumer instances in one group, and not only one, in that case the client does not know on which port to send the request to? After all, each instance is launched on a port that is selected by the OS (server.port = 0). In this case, in order for everything to work as it should, I need to add some additional services, or can I do something without them in some other way?
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
Upvotes: 0
Views: 98
Reputation: 192033
You must either hardcode the port information, or use a service discovery + load balancer service that will route requests across service instances.
For example, Consul + Fabio, or Kubernetes load balancers
Upvotes: 1