项目之间的消息传递
项目之间的消息传递都是通过RestTemplate来实现的,具体的说明可以查看spring-boot的官方手册:
其中RestTemplate.exchange可以实现HTTP的所有协议。具体调用格式
url:就是需要访问的网址
method:就是http支持的各种方法
requestEntity:http的协议主体主要包括header和body
responeType:请求的返回值
最后的请求格式:
ResponseEntity<String> entity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
在服务器端,一般在Controller层通过@RestMapping声明对应的url和method从而对请求进行响应;并通过@RequestBody来指定对应参数为消息请求中包含的消息体(body)。