Pack 0.4.0新特性解读 |集成Consul

640?wx_fmt=gif 点击上方蓝字带你去体验新特性~

ServiceComb Pack 从 0.4.0 版本开始支持将 Alpha 服务实例注册到发现服务 Consul 中,Omega 端的程序通过注册中心 Consul 就可获取Alpha 服务器实例地址。


 


640?wx_fmt=png 启动Consul 640?wx_fmt=gif


docker run -d -p 8500:8500 consul

在浏览器中访问 http://0.0.0.0:8500 ,能看到如下页面表示 Consul 启动成功

640?wx_fmt=png


640?wx_fmt=png 启动 Alpha 640?wx_fmt=gif

注册中心功能通过设置

 spring.cloud.consul.enabled=true 参数开启


 
java -jar alpha-server-0.4.0-exec.jar \	
  --server.port=8090 \	
  --alpha.server.port=8080 \	
  --spring.datasource.url="jdbc:postgresql://127.0.0.1:5432/saga?useSSL=false" \	
  --spring.datasource.username=saga-user \	
  --spring.datasource.password=saga-password \	
  --spring.cloud.consul.enabled=true \	
  --spring.cloud.consul.host=0.0.0.0 \	
  --spring.cloud.consul.port=8500 \	
  --spring.profiles.active=prd

注意: 更多 Consul 参数请参考 Spring Cloud Consul 2.x Spring Cloud Consul 1.x

Alpha 启动完毕后可以看到已经注册到 Consul

640?wx_fmt=png

执行命令行 curl http://0.0.0.0:8500/v1/agent/services 可以看到已经将 Alpha 的 gRPC 地址和端口注册到 Consul 的 Tags 中


 
{	
    "servicecomb-alpha-server-0-0-0-0-336b06581fb5b92ed91c7ade3fdafa88": {	
        "ID": "servicecomb-alpha-server-0-0-0-0-336b06581fb5b92ed91c7ade3fdafa88",	
        "Service": "servicecomb-alpha-server",	
        "Tags": [	
            "alpha-server-host=0.0.0.0",	
            "alpha-server-port=8080",	
            "secure=false"	
        ],	
        "Meta": {},	
        "Port": 8090,	
        "Address": "192.168.1.116",	
        "Weights": {	
            "Passing": 1,	
            "Warning": 1	
        },	
        "EnableTagOverride": false	
    }	
}


640?wx_fmt=png 配置Omega 端 640?wx_fmt=gif

ServiceComb Pack 0.4.0 Omega 默认依赖 Spring Boot 2.x Spring 和 Cloud Consul 2.x ,如果你的 Omega 端项目依赖 Spring Boot 1.x 你可以使用 -Pspring-boot-1 参数重新编译 Spring Boot 1.x 和 Spring Cloud Consul 1.x 的版本

修改原有 omega 端项目

增加以下依赖↓


 
<dependency>	
  <groupId>org.apache.servicecomb.pack</groupId>	
  <artifactId>omega-spring-cloud-consul-starter</artifactId>	
  <version>${pack.version}</version>	
</dependency>


在 application.yaml 添加下面的配置项


 
spring:	
  cloud:	
    consul:	
      discovery:	
        register: false	
      host: 0.0.0.0	
      port: 8500	
      	
alpha:	
  cluster:	
    register:	
      type: consul


spring bootspring-cloud-starter-consul-discovery
2.1.x.RELEASE2.1.1.RELEASE
2.0.x.RELEASE2.0.2.RELEASE

 
<dependencyManagement>	
       <dependencies>	
         <dependency>	
           <groupId>org.springframework.cloud</groupId>	
           <artifactId>spring-cloud-starter-consul-discovery</artifactId>	
           <version>2.0.2.RELEASE</version>	
         </dependency>	
       </dependencies>	
     </dependencyManagement>

 

640?wx_fmt=gif

未来,新功能还会不断加入,欢迎大家一起参与完善。共同打造优秀的微服务生态圈。

640?wx_fmt=gif

Pack 0.4.0 的重要更新


*提供Alpha HA实现

*支持使用eureka或consul进行Alpha的服务发现

*修复事件扫描线程退出的问题

640?wx_fmt=gif 640?wx_fmt=png前期阅读 ServiceComb1.2.0发布|新版本特性解读 Javachaiss1.2.0新特性解读 |使用inspector功能...


640?wx_fmt=gif 文章预告


● Pack 0.4.0新特性解读 |集成Spring Cloud Eureka

● Pack 0.4.0新特性解读 |Cluster集群实现


项目地址:

https://github.com/apache/servicecomb-pack

更多信息请浏览官网: 

http://servicecomb.apache.org/cn


640?wx_fmt=gif



长按关注 >>>盘它 640?wx_fmt=png


640?wx_fmt=png


640?wx_fmt=png 了解更多新特性请点在看 640?wx_fmt=gif 640?wx_fmt=png


“阅读原文”给Pack点个“⭐”吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值