互联网公司排名图,seo优化软件哪个最好用,网上房地产官方网,电子邮箱微服务间消息传递
微服务是一种软件开发架构#xff0c;它将一个大型应用程序拆分为一系列小型、独立的服务。每个服务都可以独立开发、部署和扩展#xff0c;并通过轻量级的通信机制进行交互。
应用开发
common模块中包含服务提供者和服务消费者共享的内容provider模块是…微服务间消息传递
微服务是一种软件开发架构它将一个大型应用程序拆分为一系列小型、独立的服务。每个服务都可以独立开发、部署和扩展并通过轻量级的通信机制进行交互。
应用开发
common模块中包含服务提供者和服务消费者共享的内容provider模块是服务的提供者用于通过SpringMVC的控制器提供访问接口 服务提供者 RestController
RequestMapping(/users)
public class HelloController {
GetMapping(/hello)
public String sayHello(RequestParam String username) {
if (username null || username.trim().length() 1)
username MicroService;
return Provider: hello username !;
}
}服务消费者 服务消费者通过http协议访问服务提供者可以使用JDK的URL或者使用HttpClient之类的工具但是直接使用工具比较繁琐所以使用SpringBoot提供的RestTemplate进行访问 在主类或者当前应用的配置类上声明RestTemplate
SpringBootApplication
public class ConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}核心配置主要修改一下访问端口号因为应用的默认端口都是8080会有端口号冲突的问题
server.port7081定义控制器实现访问服务提供者
RestController
RequestMapping(/consumer)
public class ConsumerController {
Autowired
private RestTemplate restTemplate;
GetMapping(/{name})
public String test(PathVariable String name){
//RestTemplate针对RESTful中的get/post/delete/put分别提供了对应的方法
String res
restTemplate.getForObject(http://localhost:7080/users/hello?username
name, String.class);
return res;
}
}测试验证 我们应该注意的问题
http协议的访问流程在浏览器中输入一个URL地址都发生了什么事情http协议的不同版本的区别与https的区别http协议中get和post之间的区别