安装软件
redis
环境搭建-在Windows Server 2012 R2上搭建Redis
https://www.jianshu.com/p/fdf41b1d85a1
redis Windows 版本
https://github.com/MicrosoftArchive/redis/releases
默认安装位置:
C:\Program Files\Redis
命令行执行:
redis-server.exe redis.windows.conf
redis-cli.exe
info
rabbitmq
- OTP 21.2 Windows 64-bit Binary File
http://www.erlang.org/downloads
- rabbitmq 下载地址,Windows: Installer
http://www.rabbitmq.com/download.html
两个软件都安装好后,通过如下文章开通管理UI
Windows 安装Rabbitmq
https://www.cnblogs.com/hobinly/p/6265668.html
访问地址:
http://192.168.1.121:15672/#/users
打开远程访问参考
https://blog.csdn.net/juan0728juan/article/details/77653776
新建用户,并设置对应权限
consul
下载windows 安装版本
https://www.consul.io/downloads.html
csdn用的资源是 1.4.0,我是从官网下的版本:1.4.2
https://download.csdn.net/download/zjl91dragon/10840388
新建 start-consul.bat 文件,调试模式下,启动服务器命令如下:
consul agent -dev -client 0.0.0.0
启动参数的具体意义,参见: https://blog.csdn.net/liuzhuchen/article/details/81913562 文章
中心访问地址
http://192.168.1.121:8500/ui/dc1/services
服务提供者与消费者
idea,创建项目
SpringInit / Cloud Core / Cloud Bootstrap
Consul 服务提供者
http://www.ityouknow.com/springcloud/2018/07/20/spring-cloud-consul.html
注册服务的配置文件:
spring.application.name=spring-cloud-consul-producer
server.port=8502
spring.cloud.consul.host=192.168.1.121
spring.cloud.consul.port=8500
#注册到consul的服务名称
spring.cloud.consul.discovery.serviceName=service-producer
Consul 消费者
consul 消费者调用关键代码
-
配置远端注册中心服务器地址
-
发送远程调用指令
@RestController
public class CallHelloController {
@Autowired
private LoadBalancerClient loadBalancer;
@RequestMapping("/call")
public String call() {
ServiceInstance serviceInstance = loadBalancer.choose("service-producer");
System.out.println("服务地址:" + serviceInstance.getUri());
System.out.println("服务名称:" + serviceInstance.getServiceId());
String callServiceResult = new RestTemplate().getForObject(serviceInstance.getUri().toString() + "/hello", String.class);
System.out.println(callServiceResult);
return callServiceResult;
}
}
延伸:带参数的远程调用方法等
项目配置文件代码及pom.xml 依赖库相关代码,参见博主的开源示例代码。
参考资料
参考博客
http://www.ityouknow.com/springcloud/2018/07/20/spring-cloud-consul.html
Spring Cloud Eureka Consul使用和对比
https://blog.csdn.net/ZYC88888/article/details/81453647
consul 与 eureka
https://blog.csdn.net/baidu_36327010/article/details/80363703