CARVIEW |
Select Language
HTTP/2 200
date: Tue, 29 Jul 2025 01:17:15 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"cd7b9445ebb3c915b3196b47f525e6d3"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=9mcIbx5xj7xzplIPSAz20TxpXnsGXiLgnxHuakV9XfpKPvfAYT%2Bcnq7cus8Ut4mE7DTgG%2B7QMpnvlIrI7N%2Fr3EwJHhta5yE0hwDwVvX0lnDJTxV5iqelXyFGItTL3CLpDmytdZ6yIeM1M3ZzJZPU5UXSxDgp2DAmxW7QzBQEdQwY5Sfr%2FVEpI%2F%2FOdevVDrPIlyIxy9by7bPhogV0tbteYbZcJnjPZK%2B8hX8Yyv3tIElzePDDvHawKlikM82Qfo0ZqVnPu1S%2B8HXnUa5s9JQIig%3D%3D--SCVyZFCFMl16hSke--TNnWTWNxDcu18LqyUaP%2BKQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1177376101.1753751832; Path=/; Domain=github.com; Expires=Wed, 29 Jul 2026 01:17:12 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Wed, 29 Jul 2026 01:17:12 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: CD8C:339E63:B022C:118AF0:68882118
Multi registration and multi discovery · Tencent/spring-cloud-tencent Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 508
Multi registration and multi discovery
Haotian Zhang edited this page Apr 13, 2023
·
16 revisions
当使用者想要使用多个服务注册中心,或者是想从其他注册中心平滑迁移到 Polaris 时,一种实现方式是在客户端侧多注册多发现。为了实现多注册多发现的能力,同时尽可能的对业务无侵入,polaris-java-sdk 封装了多注册多发现的功能,使用者可以轻松地实现该场景。
目前仅支持 Polaris 与 Consul / Nacos 的多注册和多发现。
如上图所示,polaris-java-sdk
实现了多注册多发现的能力,业务应用只需对接 Polaris 的服务发现能力即可。Polaris 可以同时对 Consul 或者 Nacos 进行多注册和多发现。因此,需要增加其他注册中心的相关配置以建立注册发现连接。
如果您的项目里依赖了 spring-cloud-starter-consul-discovery
,则需要删除依赖,否则会导致应用启动失败。启动失败日志如下:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field autoServiceRegistratihaiyon in org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration required a single bean, but 2 were found:
- polarisAutoServiceRegistration: defined by method 'polarisAutoServiceRegistration' in class path resource [com/tencent/cloud/polaris/registry/PolarisServiceRegistryAutoConfiguration.class]
- consulAutoServiceRegistration: defined by method 'consulAutoServiceRegistration' in class path resource [org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationAutoConfiguration.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>connector-consul</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId>
<version>${version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>connector-consul</artifactId>
</dependency>
- 配置完整的
spring cloud polaris discovery
配置 - 配置完整的
spring cloud consul discovery
配置,注意需要打开所有的开关,包括:- spring.cloud.consul.enabled
- spring.cloud.consul.discovery.register
- spring.cloud.consul.discovery.enabled
一份完整配置的样例如下所示:
spring:
application:
name: DiscoveryCalleeService
cloud:
polaris:
address: grpc://127.0.0.1:8091 # 需修改为真实的 Polaris 服务地址
discovery:
ip-address: 127.0.0.1
consul:
port: 8500
host: 127.0.0.1
enabled: true # 需要打开
discovery:
register: true # 需要打开
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port}
enabled: true # 需要打开
service-name: ${spring.application.name}
ip-address: localhost
prefer-ip-address: true
配置项Key | 默认值 | 是否必填 | 配置项说明 |
---|---|---|---|
spring.cloud.consul.host | 无 | 是 | Consul后端地址 |
spring.cloud.consul.port | 无 | 是 | Consul端口号 |
spring.cloud.consul.enabled | true | 否 | 是否启用Consul |
spring.cloud.consul.discovery.enabled | true | 否 | 是否启用Consul服务发现 |
spring.cloud.consul.discovery.register | true | 否 | 是否启用Consul服务注册 |
spring.cloud.consul.discovery.service-name | ${spring.application.name} | 否 | 注册服务名 |
spring.cloud.consul.discovery.instance-id | 服务名-IP-端口号 | 否 | 注册实例ID |
spring.cloud.consul.discovery.prefer-ip-address | false | 否 | 是否使用自定义IP注册 |
spring.cloud.consul.discovery.ip-address | 无 | 否 | 自定义注册IP |
如果您的项目里依赖了 Nacos 相关,则需要删除依赖,否则会导致应用启动失败。
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>connector-nacos</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId>
<version>${version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>connector-nacos</artifactId>
</dependency>
- 配置完整的
spring cloud polaris discovery
配置 - 配置完整的
spring cloud nacos discovery
配置,注意需要打开所有的开关,包括:- spring.cloud.nacos.enabled
- spring.cloud.nacos.discovery.enabled
- spring.cloud.nacos.discovery.register-enabled
一份完整配置的样例如下所示:
spring:
application:
name: DiscoveryCalleeService
cloud:
polaris:
address: grpc://127.0.0.1:8091 # 需修改为真实的 Polaris 服务地址
discovery:
ip-address: 127.0.0.1
nacos:
enabled: true
discovery:
server-addr: 127.0.0.1:8848
enabled: true
register-enabled: true
username: nacos
password: nacos
group: polaris
cluster-name: DEFAULT
配置项Key | 默认值 | 是否必填 | 配置项说明 |
---|---|---|---|
spring.cloud.nacos.enabled | true | 否 | 是否启用 Nacos |
spring.cloud.nacos.discovery.server-addr | 无 | 是 | Nacos 后端地址 |
spring.cloud.nacos.discovery.enabled | true | 否 | 是否启用 Nacos 服务发现 |
spring.cloud.nacos.discovery.register-enabled | true | 否 | 是否启用 Nacos 服务注册 |
spring.cloud.nacos.discovery.username | 无 | 否 | 用户名 |
spring.cloud.nacos.discovery.password | 无 | 否 | 密码 |
spring.cloud.nacos.discovery.group | DEFAULT_GROUP | 否 | 服务分组 |
spring.cloud.nacos.discovery.cluster-name | DEFAULT | 否 | 集群名称 |
- 您在使用过程中遇到任何问题,请提 Issue 或者加入我们的开发者群告诉我们,我们会在第一时间反馈
- Spring Cloud Tencent 社区期待您的加入,一个 Star、PR 都是对我们最大的支持
- 项目介绍
- 使用指南
- 最佳实践
- 开发文档
- 学习资料
Clone this wiki locally
You can’t perform that action at this time.