Alberto
Alberto

Reputation: 45

How does it connect various microservices with Docker?

I have two microservices into Docker and I want to connect one with other, but I don´t know to do it. The two (and the future apps) are API Rest with Spring-boot, I am searching info, tutorials... but I don`t see nothing. My idea is have an main app that it is be able to connect with the other microservices that they are API Rest and afterwards this main app publish and all this I want to have it inside of the container (Docker).

Is it possible?

Anyone knows any tutorial that explain this?

Thanks so much!

Upvotes: 2

Views: 1310

Answers (2)

Constantin Galbenu
Constantin Galbenu

Reputation: 17683

What you are describing could be an API Gateway. Here is a great tutorial explaining this pattern.

Implement an API gateway that is the single entry point for all clients. The API gateway handles requests in one of two ways. Some requests are simply proxied/routed to the appropriate service. It handles other requests by fanning out to multiple services.

enter image description here

A variation of this pattern is the Backend for Front-End pattern. It defines a separate API gateway for each kind of client.

enter image description here

Using an API gateway has the following benefits:

  • Insulates the clients from how the application is partitioned into microservices

  • Insulates the clients from the problem of determining the locations of service instances

  • Provides the optimal API for each client

  • Reduces the number of requests/roundtrips. For example, the API gateway enables clients to retrieve data from multiple services with a single round-trip. Fewer requests also means less overhead and improves the user experience. An API gateway is essential for mobile applications.

  • Simplifies the client by moving logic for calling multiple services from the client to API gateway

  • Translates from a “standard” public web-friendly API protocol to whatever protocols are used internally

The API gateway pattern has some drawbacks:

  • Increased complexity - the API gateway is yet another moving part that must be developed, deployed and managed

  • Increased response time due to the additional network hop through the API gateway - however, for most applications the cost of an extra roundtrip is insignificant.

How implement the API gateway?

An event-driven/reactive approach is best if it must scale to scale to handle high loads. On the JVM, NIO-based libraries such as Netty, Spring Reactor, etc. make sense. NodeJS is another option.

Upvotes: 4

Aggarat .J
Aggarat .J

Reputation: 509

Just give you the simplest answer: In general containers can communicate among each others with any protocols (http,ftp,tcp,udp) not limit to only rest(http/s)

  1. using the internal/ external IPs and ports
  2. using the internal/ external names (dns):
    • in your Micro-service is in the same cluster on multi-host -> you should be able to write the program in your Springboot to call http://{{container service name}} , It's the built-in feature of containers
    • if you have more microservices in different cluster or hosts or the internet , you can use APIM (API management) or reverse-proxy(NGINX,HAProxy) to manages the service name eg. microservice1.yourdomain.com —> container1 or service1(cluster) microservice2.yourdomain.com —> container2 or service 2(cluster) yourdomain.com/microservice1—> container2 or service 2(cluster) yourdomain.com/microservice2—> container1 or service1(cluster)

PS . there are more sophisticated techniques out there but it fundamentally come down above approaches.

Upvotes: 3

Related Questions