Parenthood and the Workplace

If you were recruiting someone for your company, who would you prefer; someone with children, or without? Or would you not mind? Instead, would you be focused on their skills and experience? Or maybe…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Microservices communication in Spring Boot with Feign client

Communicate two microservices with HTTP protocol

Microservices is one of those architectural patterns which has emerged from the world of domain-driven design, and its many applications communicate with each other to form a complete application. The common protocol used for that reason is Http/Https. By the end of this article, you will learn how to communicate microservices in a Spring Boot application using Feign — a declarative HTTP client developed by Netflix.

I assume that you have already two microservices(if not you will find the source code below), so I will jump directly to implementation. For this example, I two microservices(one is a UserServiceApp second is an ItemServiceApp).

I will create a service that calls a list of user items in ItemServiceApp.

To use Feign, we need to add the needed dependencies:

Then add @EnableFeignClients annotation in the main Application.class

In ItemsServiceApp there is an API that fetches a list of items by user ID.

Now to consume this in UserServiceApp, we need an Interface service and add @FeignClient annotation with the name of the microservice defined in application.properties

The path value in @GetMapping is the path of the API in ItemsServiceApp.

The service will look like that:

Now, we can call the getItemByUserId() method in UserService.

That is all, not that complicated, right!

If you face any problem, please write it in the comment.

Resources:

Add a comment

Related posts:

3 Things that Made me Want to Marry my Girlfriend

Who could even imagine that I will ever be married? Probably no one. I, myself, also didn’t expect it at all. I met her when I was in my middle 20s. I was in college, and so was she. She came to my…

Trusting the Process

I am writing to remind you of things you already know. When you feel lost and confused, like you are wandering around in a hopeless wilderness, know that you are not alone. Love goes before you and…

Unfathomable Love?

All we like are happy faces and high peaks of enthusiasm but fail to appreciate the innermost realities of the people we love. We detest and walk away from the people whom we’ve loved when they take…