how to request data from our spring boot micro-service to external server for a given id's?
Currently I have created 2 microservices and and getting the data from one service to another using RestTemplate.
Microservice -1:
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
public class StringDataController {
List<String> stringList = new ArrayList<>();
@RequestMapping(value = "/securities/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<String> sendStringData(){
stringList.add("12345");
stringList.add("23435");
stringList.add("23436");
return stringList;
}
}
Microservice-2:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List;
@RestController
@EnableAutoConfiguration
public class ExternalRequestController {
@Value ("${sampleMS1.uri}")
String sampleMS1URI;
@RequestMapping(value="/listdata", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void receiveStringFromAnotherMS(){
List<String> list = null;
list = new RestTemplate().getForObject(sampleMS1URI,List.class);
System.out.println(list.toString());
System.out.println("-->"+list);
}
}
Now, I have to send the List(String)(list of ID's) data to some external server and response should get Map(K,V) ==> key as a String and Value as a Double.
Note: The external server is not handling by us, so we can only request the data with List of id's and then they should sending the response with price data of specific id's.
Can anyone suggest me a way to do it ?
I am new to Spring & Spring boot.
Thank you!
spring-boot resttemplate
|
show 3 more comments
Currently I have created 2 microservices and and getting the data from one service to another using RestTemplate.
Microservice -1:
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
public class StringDataController {
List<String> stringList = new ArrayList<>();
@RequestMapping(value = "/securities/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<String> sendStringData(){
stringList.add("12345");
stringList.add("23435");
stringList.add("23436");
return stringList;
}
}
Microservice-2:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List;
@RestController
@EnableAutoConfiguration
public class ExternalRequestController {
@Value ("${sampleMS1.uri}")
String sampleMS1URI;
@RequestMapping(value="/listdata", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void receiveStringFromAnotherMS(){
List<String> list = null;
list = new RestTemplate().getForObject(sampleMS1URI,List.class);
System.out.println(list.toString());
System.out.println("-->"+list);
}
}
Now, I have to send the List(String)(list of ID's) data to some external server and response should get Map(K,V) ==> key as a String and Value as a Double.
Note: The external server is not handling by us, so we can only request the data with List of id's and then they should sending the response with price data of specific id's.
Can anyone suggest me a way to do it ?
I am new to Spring & Spring boot.
Thank you!
spring-boot resttemplate
Can you elaborate what exactly you have tried and what is not working?
– Wim Deblauwe
Nov 14 '18 at 11:04
Hi Wim, I am not sure how I can request to external server with the list of id's. I have googled it and stackoverflow also I have searched but I didn't find anything related to my query. whatever results I have found is related to communication between 2 micro-services.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:18
May be I am still at a beginner level to understand it.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:19
Do you know how you can talk to that external server? Do you need to send JSON? And why are you showing 2 microservices here? Is one of the 2 the external one?
– Wim Deblauwe
Nov 14 '18 at 11:56
1
the API documentation for the external API should mention how you can send the list to them it can be in the body or in a file that you should get answers from who ever owns the external API. it cannot be something that you just write.
– Grinish Nepal
Nov 14 '18 at 15:57
|
show 3 more comments
Currently I have created 2 microservices and and getting the data from one service to another using RestTemplate.
Microservice -1:
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
public class StringDataController {
List<String> stringList = new ArrayList<>();
@RequestMapping(value = "/securities/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<String> sendStringData(){
stringList.add("12345");
stringList.add("23435");
stringList.add("23436");
return stringList;
}
}
Microservice-2:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List;
@RestController
@EnableAutoConfiguration
public class ExternalRequestController {
@Value ("${sampleMS1.uri}")
String sampleMS1URI;
@RequestMapping(value="/listdata", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void receiveStringFromAnotherMS(){
List<String> list = null;
list = new RestTemplate().getForObject(sampleMS1URI,List.class);
System.out.println(list.toString());
System.out.println("-->"+list);
}
}
Now, I have to send the List(String)(list of ID's) data to some external server and response should get Map(K,V) ==> key as a String and Value as a Double.
Note: The external server is not handling by us, so we can only request the data with List of id's and then they should sending the response with price data of specific id's.
Can anyone suggest me a way to do it ?
I am new to Spring & Spring boot.
Thank you!
spring-boot resttemplate
Currently I have created 2 microservices and and getting the data from one service to another using RestTemplate.
Microservice -1:
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
public class StringDataController {
List<String> stringList = new ArrayList<>();
@RequestMapping(value = "/securities/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<String> sendStringData(){
stringList.add("12345");
stringList.add("23435");
stringList.add("23436");
return stringList;
}
}
Microservice-2:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List;
@RestController
@EnableAutoConfiguration
public class ExternalRequestController {
@Value ("${sampleMS1.uri}")
String sampleMS1URI;
@RequestMapping(value="/listdata", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void receiveStringFromAnotherMS(){
List<String> list = null;
list = new RestTemplate().getForObject(sampleMS1URI,List.class);
System.out.println(list.toString());
System.out.println("-->"+list);
}
}
Now, I have to send the List(String)(list of ID's) data to some external server and response should get Map(K,V) ==> key as a String and Value as a Double.
Note: The external server is not handling by us, so we can only request the data with List of id's and then they should sending the response with price data of specific id's.
Can anyone suggest me a way to do it ?
I am new to Spring & Spring boot.
Thank you!
spring-boot resttemplate
spring-boot resttemplate
edited Nov 14 '18 at 16:20
Xenis
15516
15516
asked Nov 14 '18 at 11:02
Nageswara Rao RamisettyNageswara Rao Ramisetty
114
114
Can you elaborate what exactly you have tried and what is not working?
– Wim Deblauwe
Nov 14 '18 at 11:04
Hi Wim, I am not sure how I can request to external server with the list of id's. I have googled it and stackoverflow also I have searched but I didn't find anything related to my query. whatever results I have found is related to communication between 2 micro-services.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:18
May be I am still at a beginner level to understand it.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:19
Do you know how you can talk to that external server? Do you need to send JSON? And why are you showing 2 microservices here? Is one of the 2 the external one?
– Wim Deblauwe
Nov 14 '18 at 11:56
1
the API documentation for the external API should mention how you can send the list to them it can be in the body or in a file that you should get answers from who ever owns the external API. it cannot be something that you just write.
– Grinish Nepal
Nov 14 '18 at 15:57
|
show 3 more comments
Can you elaborate what exactly you have tried and what is not working?
– Wim Deblauwe
Nov 14 '18 at 11:04
Hi Wim, I am not sure how I can request to external server with the list of id's. I have googled it and stackoverflow also I have searched but I didn't find anything related to my query. whatever results I have found is related to communication between 2 micro-services.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:18
May be I am still at a beginner level to understand it.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:19
Do you know how you can talk to that external server? Do you need to send JSON? And why are you showing 2 microservices here? Is one of the 2 the external one?
– Wim Deblauwe
Nov 14 '18 at 11:56
1
the API documentation for the external API should mention how you can send the list to them it can be in the body or in a file that you should get answers from who ever owns the external API. it cannot be something that you just write.
– Grinish Nepal
Nov 14 '18 at 15:57
Can you elaborate what exactly you have tried and what is not working?
– Wim Deblauwe
Nov 14 '18 at 11:04
Can you elaborate what exactly you have tried and what is not working?
– Wim Deblauwe
Nov 14 '18 at 11:04
Hi Wim, I am not sure how I can request to external server with the list of id's. I have googled it and stackoverflow also I have searched but I didn't find anything related to my query. whatever results I have found is related to communication between 2 micro-services.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:18
Hi Wim, I am not sure how I can request to external server with the list of id's. I have googled it and stackoverflow also I have searched but I didn't find anything related to my query. whatever results I have found is related to communication between 2 micro-services.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:18
May be I am still at a beginner level to understand it.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:19
May be I am still at a beginner level to understand it.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:19
Do you know how you can talk to that external server? Do you need to send JSON? And why are you showing 2 microservices here? Is one of the 2 the external one?
– Wim Deblauwe
Nov 14 '18 at 11:56
Do you know how you can talk to that external server? Do you need to send JSON? And why are you showing 2 microservices here? Is one of the 2 the external one?
– Wim Deblauwe
Nov 14 '18 at 11:56
1
1
the API documentation for the external API should mention how you can send the list to them it can be in the body or in a file that you should get answers from who ever owns the external API. it cannot be something that you just write.
– Grinish Nepal
Nov 14 '18 at 15:57
the API documentation for the external API should mention how you can send the list to them it can be in the body or in a file that you should get answers from who ever owns the external API. it cannot be something that you just write.
– Grinish Nepal
Nov 14 '18 at 15:57
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298686%2fhow-to-request-data-from-our-spring-boot-micro-service-to-external-server-for-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298686%2fhow-to-request-data-from-our-spring-boot-micro-service-to-external-server-for-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you elaborate what exactly you have tried and what is not working?
– Wim Deblauwe
Nov 14 '18 at 11:04
Hi Wim, I am not sure how I can request to external server with the list of id's. I have googled it and stackoverflow also I have searched but I didn't find anything related to my query. whatever results I have found is related to communication between 2 micro-services.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:18
May be I am still at a beginner level to understand it.
– Nageswara Rao Ramisetty
Nov 14 '18 at 11:19
Do you know how you can talk to that external server? Do you need to send JSON? And why are you showing 2 microservices here? Is one of the 2 the external one?
– Wim Deblauwe
Nov 14 '18 at 11:56
1
the API documentation for the external API should mention how you can send the list to them it can be in the body or in a file that you should get answers from who ever owns the external API. it cannot be something that you just write.
– Grinish Nepal
Nov 14 '18 at 15:57