-1

I'm new to the JavaEE Micro-service(Maven) technique/Architecture, and I have written two services.

Now I am trying to figure out how to make these services communicate - what methods to use.

To make it clearer: if I wanted to pass a simple string from Microservice A to Microservice B, how would I archive that?

kryger
  • 12,906
  • 8
  • 44
  • 65
Muzi Jack
  • 788
  • 1
  • 7
  • 20
  • Http, or regular sockets, it depends on your wants and needs – Software Person Jun 27 '19 at 10:19
  • 1
    Duplicate https://stackoverflow.com/questions/50506101/spring-boot-how-to-communicate-between-microservices – Vikram R Jun 27 '19 at 10:21
  • I saw that post question and they using Spring Boot. now question is can i achieve the same thing using just Maven? – Muzi Jack Jun 27 '19 at 10:24
  • You can read this answer I posted it covers way how the communication can be done. https://stackoverflow.com/a/56656955/1775693 Check the section "Communication between micro-services". – xargs Jun 27 '19 at 12:27

1 Answers1

0

The common way to do it is to select a JSON protocol that the two sides transfer between each other, For example:

{
 fName: "Sean",
 lName: "Mellony"
}

And then to make HTTP calls to GET or POST data between your two micro-services.

For example, the server service will have a POST endpoint that the other service will call with an HTTP client.

By doing so, you are free to change the implementation on each side (let's say you discover that you better write your service A in JavaScript and the service B in Java).

As long as both sides keep working with the same protocol, they are agnostic to the implementation that the other side uses.

riorio
  • 6,500
  • 7
  • 47
  • 100
  • so i can just use HttpClient to listen to the other Service? – Muzi Jack Jun 27 '19 at 10:28
  • @muzijack not exactly. I updated my answer. you will need a relevant endpoint in the "server" service. HttpClient will be used to call the endpoint in the server – riorio Jun 27 '19 at 10:32
  • @muzijack if you find my answer useful, I'll appreciate getting your kudos – riorio Jun 27 '19 at 11:07
  • in this case i have both services in Java and example would be passing a string from that one service to the other. and Micro-service B would receive the request with the response e.g {value: "string-passed-from-service-B"} – Muzi Jack Jun 27 '19 at 11:15
  • ur comment was very helpful it gives me an idea. but can you please share a link with these examples. – Muzi Jack Jun 27 '19 at 11:16
  • @muzijack maybe you can start your R&D here - https://spring.io/guides/gs/spring-boot/ – riorio Jun 27 '19 at 11:23