How do I retrieve information from one microservice into another? When should I use Kafka vs a WebClient?

There are two ways to achieve this:

  • Via Kafka/PubSub (Spring Messaging)
  • Via WebClient

Depending on the mechanism used, the implementations differ.

WebClient flows are typically used when an immediate response is needed. Whereas Kafka is used for asynchronous messaging where timing is less important. WebClient and Kafka both can still be used even if the services are in the same flex package or in different ones.

For WebClient, in order to retrieve data from ServiceB into ServiceA via a web client, you need to implement a Provider in ServiceA which would make an HTTP request to an endpoint in ServiceB. For more details, you can visit Broadleaf Dev Central

For messaging, a Producer and Consumer binding has to be established. Messages are sent over a channel by the Producer and are consumed by the Handlers/Listeners. More details about its configuration and setup can be found at Broadleaf Dev Central