Spring Boot - how to communicate between microservices?

后端 未结 6 2147
天涯浪人
天涯浪人 2021-02-07 15:41

I\'m currently working on a Spring Boot microservices project. I have created services and each service is running separately. With this, I need some services to communicate wit

6条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 16:28

    As mentioned by @g00glen00b in comments Eureka is not used for communication between microservices. Its for service discovery. There are two ways that I know ofthrough which you can communicate with other Microservices :

    1. RestTemplate
    2. Feign Client

    RestTemplate is very simple to use. It does not require configurations.

    e.g.

       ResponseType obj=  new RestTemplate().getForObject(URL, ResponseType.class, params);
    

    url - the URL

    responseType - the type of the return value

    params- the variables to expand the template

    Spring Doc link for your reference

提交回复
热议问题