19622

Call Microservice from another Microservice within Docker

Question:

I created several Microservices in C# that are running on docker in windows, I need to call Microservice from another Microservice so I used this way to call:

[HttpGet("GetOrder/{Object_ID}")] public Order GetOrder (int id) { string Baseurl = "http://189.29.0.100/"; ….. using (var client = new HttpClient()) { //Passing service base url client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); //Define request data format client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Sending request to find web api REST service resource GetAllEmployees using HttpClient borrowerData = await client.GetStringAsync("api/order/" + Id.ToString()); } … }

I used the fix IP in Composed file as follows:

orderservice: environment: - ASPNETCORE_ENVIRONMENT=Development ports: - "80" networks: default: ipv4_address: 189.29.0.100

The problem is when we deploy this project in VM, how to make it work with these Ips?

Answer1:

Docker compose create a virtual network on you host and the services are not routable from outside of docker with those IPs. But inside the virtual network all services can access to each other with their names (http://otherservice/). If you want to access to all deployed microservices on VM you will need a reverse proxy inside your docker compose. For example an nginx service that dispatch request to other services.

Recommend

  • Ways to determine returning “anonymous” guests in PHP
  • How to change footer of a particular page with a particular header title in TCPDF
  • Saved Core Data does not persist after app closes 80% of the time
  • Matplotlib: subplot
  • Getting SPI temperature data from outside of class
  • HTTPS request/response in Android
  • In an Outlook addin, how to check whether we are in compose mode or read mode?
  • Show QMainwindow in the middle of the screen
  • REGEXP_REPLACE pattern has to be const? Comparing strings in BigQuery
  • Old data appears in SQLite database when reinstalling app
  • How to get a Builder object from rows related to pivot - Laravel
  • How to create 2 svg's on one page?
  • AppEngine Paypal integration giving SSLCertificateError on localhost, using Python
  • Windows 8 Flexboxes - Nesting Flexboxes with overflow enabled
  • device tree overlay phandle
  • Hiding prices based on visitor location backend bug in Woocommerce
  • configure openjpa on to spring boot
  • How to adapt DirectX-style world/view/projection matrices to OpenGL?
  • Background beacon detection and Notification (Both iOS and Android) for Eddystone beacon?
  • Azure NodeJS Error: ENOENT, open 'D:\\home\\site\\wwwroot\\bin\\views\\'
  • Passing HTTP Post from AWS API GW to Lambda
  • Test for NULLs in multiple columns in MySQL
  • How to implement Google Drive and Google Plus sdk in ios project
  • Query regarding com.jcraft.jsch.JSchException: UnknownHostKey: x.y.com. DSA key fingerprint is “ac:e
  • How to display content depending on dropdown menue user selection
  • how to add dashed border on highcharts “area” graph for every point
  • separate tokens in batch file
  • Building JavaFX 2.0 App on Mac, deploying on Windows
  • Query takes almost two seconds but matches only two rows - why isn't the index helping?
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • How to join two tables from different databases
  • Ruby regex for matching simpliest Ruby's regexes
  • Zoho API: Get the user that is making the request
  • Print Longitude and Latitude in textbox Android
  • iphone image to video issue in video speed
  • How to integrate angular2-material (alpha 8.2) with angular2-Quickstart app
  • php “page caching” solution suggestions for CMS Applications
  • Jersey serializes character value to ASCII equivalent numeric string
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?