Consul Versions | HashiCorp Releaseshttps://releases.hashicorp.com/consul/
2、启动consul agent -dev
3、默认地址localhost:8500
服务提供者 pomymlorg.example cloud-api-commons1.0-SNAPSHOT org.springframework.cloud spring-cloud-starter-consul-discoveryorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-actuatororg.springframework.boot spring-boot-devtoolsruntime true org.projectlombok lombokorg.springframework.boot spring-boot-starter-test
server:
port: 8006
spring:
application:
name: consul-provider-payment
cloud:
consul:
discovery:
service-name: ${spring.application.name}
host: localhost
port: 8500
主启动
@SpringBootApplication
@EnableDiscoveryClient
public class PaymentMain8006 {
public static void main(String[] args){
SpringApplication.run(PaymentMain8006.class,args);
}
}
controller
@RestController
@Slf4j
public class PaymentController {
@Value("${server.port}")
private String serverPort;
@RequestMapping("/payment/consul")
public String paymentConsul(){
return "cloud with consul"+ serverPort+ UUID.randomUUID();
}
}
服务消费者类似于提供者
pom和yml内容大致相同
ap(Eureka):高可用、分区容错性
cp(zookeeper、Consul):强一致性,分区容错性



