Javatpoint Logo
Javatpoint Logo

Setting up Currency Conversion Microservice

In the previous section, we have created currency-exchange-service. Now we will create a currency-conversion-service that talks to currency-exchange-service.

Step 1: Open the browser and type

  • Provide the Group name javatpoint.microservice and Artifact currency-conversion-service.
  • Add the dependencies: Spring web, DevTools, Actuator, and Config Client.
  • Click on the Generate It downloads the created project.
Setting up Currency Conversion Microservice

Step 2: Import the downloaded project in Spring Tool Suite (STS).

File -> Import -> Existing Maven Projects -> Next -> Browse -> Select the project -> Finish.

It takes some time to import the project.

Step 3: Open the file and configure the application name and port number.

The currency-conversion-service runs on port 8100.

Setting up Currency Conversion Microservice

In the next section, we will create a service that talks to the currency-exchange-service.

Creating a Service for currency-conversion-service

In the previous section, we have used EUR to INR that returns what the conversionMultiple is. The currency-exchange-service tells what is the exchange value when we convert currency from EUR to INR.

In this section, we will create CurrencyCalculationService. It defines a lot of functionality related to conversion.

We will create a service currency-converter that accepts two path parameters "from" and "to". It also accepts the quantity (amount which we want to convert).

Let's create a currency-conversion-service.

Step 1: Create a class with the name CurrencyConversionController.

Step 2: Add an annotation @RestController.

Step 3: Create a GetMapping.

Step 4: Create a class with the name CurrencyConversionBean and define the following fields:

Step 5: Generate Getters and Setters.

Step 6: Generate constructor and also create a default constructor.

Step 7: Restart the application and type the following URI in the browser:


Setting up Currency Conversion Microservice

In the above response, "from," "to," and "quantity" variables picked up from the path. We have hardcoded the other variables.

In the next step, from the currency-conversion-service, we will call the currency-exchange-service. We will also determine what the conversion multiple is, and will use that amount (conversion multiple) to calculate the total amount. We will also use the port that comes in the response.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA