[英]communication between 2 rest web services
I have many rest controllers in my project (developed with spring MVC) and i would like to make them communicate between each other. 我的项目中有很多rest控制器(使用spring MVC开发),我想让它们彼此通信。 what's the best way to make two spring REST controllers exchange messages ?
使两个spring REST控制器交换消息的最佳方法是什么?
Supposed you have 2 controllers: 假设您有2个控制器:
@RestController
@RequestMapping("/first")
public class FirstController(){
// your code here
}
and 和
@RestController
@RequestMapping("/second")
public class SecondController(){
// supposed this is your FirstController url.
String url = "http://localhost:8080/yourapp/first";
// create request.
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
// execute your request.
HttpResponse response = client.execute(request);
// do whatever with the response.
}
For reference, have a look at this: http://www.mkyong.com/java/apache-httpclient-examples/ 作为参考,请看一下: http : //www.mkyong.com/java/apache-httpclient-examples/
Used library: https://hc.apache.org/httpcomponents-client-ga/ 二手图书馆: https : //hc.apache.org/httpcomponents-client-ga/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.