Spring Boot - how to communicate between microservices?

后端 未结 6 2031
逝去的感伤
逝去的感伤 2021-02-07 15:59

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:40

    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

提交回复
热议问题