Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore Microservices Lab Manual

Microservices Lab Manual

Published by Teamlease Edtech Ltd (Amita Chitroda), 2022-08-30 11:47:28

Description: Microservices Lab Manual

Search

Read the Text Version

JAVA MicroServices FULL STACK DEVELOPMENT

Objectives of this Lab Manual This lab manual includes - Exercises for hands on practice Guidelines to complete the exercise Learning Outcome

Microservices

Problem Statement What will you do? Write a Program to invoke Microservices using feign.

Solution What will be the steps steps to get the output? • Step-1: Select currency exchange project • Step-2: Open the pom.xml and add the Feign dependency. • Step-3: After the dependency has been installed, add the annotation @EnableFeignClients to the CurrencyExchangeApplication.java file to allow the Feign to scan the clients. • Step-4: Create a new attribute and annotate it with @EnableFeignClients. The package name that we wish to scan is the attribute. • Step-5: Make a feign proxy so we can communicate with outside microservices. Make a new interface called CurrencyExchangeServiceProxy. • Step-6: Add an annotation @FeignClient. Pass the attributes name and URL.

Solution What will be the steps steps to get the output? • Step-7: In order to communicate with the currency exchange controller, a method must now be defined. The Currency-ConverterController.java file should be opened. Copy the mapping for the currency converter, then put it in the same file. • Step-8: Use CurrencyExchangeServiceProxy and wire it automatically. • Step-9: Execute the feign service by using the URL . It returns the same response as currency-Exchanger.

Code <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> <version>1.4.4.RELEASE</version> </dependency> package com.javatpoint.microservices.currencyconversionservice; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients;

Code public class CurrencyExchangerApplication { public static void main(String[] args) { SpringApplication.run(CurrencyExchangerApplication.class, args); } } @FeignClient(name=\"currency-exchange-service\", url=\"localhost:number\") @Autowired private CurrencyExchangeServiceProxy proxy;

Output Output for the Adedxetercxitsheewreil:l- be :-

Learning Outcome After Performing AddTtheixst Ehxeererc:-ise You’ll be able to Write a Program to invoke Microservices using feign.

Happy Learning!


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook