私は領事ファーストセットアップを使用しています。このために、ポート 8500 が 8500 にマップされた consul docker イメージを使用しているため、ローカル セットアップで正常に使用できます。 http://localhost:8500で consul にアクセスできます。
構成サーバー には次の構成があります-pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
アプリケーション.yml
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/xxxxxx/spring-config-repo.git
consul:
host: consul
port: 8500
enabled: true
discovery:
enabled: true
register: true
service-name: configservice
ブートストラップ.yml
spring:
application:
name: config-server
ConfigServerApplication.java
@EnableConfigServer
@EnableDiscoveryClient
@SpringBootApplication
public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
この jar を実行すると、成功します。consul ui で構成サーバーを確認できます。以下は、consul から見た構成サーバーの詳細です。
Request - http://localhost:8500/v1/catalog/services
Response -
{
"configservice": [],
"consul": []
}
Request - http://localhost:8500/v1/catalog/service/configservice
Response -
[
{
"ID": "f6ac953c-07b9-4097-974e-3ea9cd39bec2",
"Node": "a0954c644062",
"Address": "127.0.0.1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "127.0.0.1"
},
"NodeMeta": {},
"ServiceID": "config-server-8888",
"ServiceName": "configservice",
"ServiceTags": [],
"ServiceAddress": "10.0.0.158",
"ServicePort": 8888,
"ServiceEnableTagOverride": false,
"CreateIndex": 15,
"ModifyIndex": 15
}
]
この uri- を使用して構成サーバーにアクセスすることもできます。
http://localhost:8888/configclient/default
構成サーバーのプロパティを使用するクライアント アプリケーションがあります。私の理解では、この jar を実行すると、consul に接続し、そこから構成サーバー情報を取得し、指定された git uri からフェッチしてプロパティを設定します。
以下は、クライアントに関する詳細です - pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
ブートストラップ.yml
spring:
application:
name: myservice
cloud:
config:
fail-fast: true
retry:
max-attempts: 20
initial-interval: 3000
enabled: true
discovery:
enabled: true
service-id: configserver
consul:
host: localhost
port: 8500
discovery:
enabled: true
register: true
service-name: myservice
アプリケーション.yml
server:
port: 8081
MyServiceApplication.java
@EnableDiscoveryClient
@SpringBootApplication
public class MyServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ApplePaymentServiceApplication.class, args);
}
}
しかし、このjarのこの起動中に、構成サーバーを見つけることができず、代わりにデフォルトの uri にフォールバックします。これは、関連する起動ログ セクションです。
2017-03-28 00:40:20.407 WARN 99123 --- [ main] lientConfigServiceBootstrapConfiguration : No instances found of configserver (configserver)
2017-03-28 00:40:20.551 INFO 99123 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='consul', propertySources= . [ConsulPropertySource [name='config/myservice/'], ConsulPropertySource [name='config/application/']]]
2017-03-28 00:40:20.587 INFO 99123 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
2017-03-28 00:40:21.831 INFO 99123 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=myservice, profiles=[default], label=null, version=null, state=null
2017-03-28 00:40:21.832 INFO 99123 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='https://github.com/xxxxx/spring-config-repo.git/myservice.yml'], MapPropertySource [name='https://github.com/xxxxx/spring-config-repo.git/application.yml']]]
2017-03-28 00:40:21.841 INFO 99123 --- [ main] c.h.MyServiceApplication : No active profile set, falling back to default profiles: default
spring cloud configを使用したconsulの最初のブートストラップなど、さまざまな例からさまざまなオプションをいじりました
誰かが私が見逃しているかもしれないものを指摘できますか? consul、configserver、および client の適切なアプリケーション/ブートストラップ ファイルにアクセスできる実際の例へのポインタは、最も役立ちます。
PS: 質問の情報過多についてお詫び申し上げます。関係のないものもあるかもしれませんが、できるだけ多くの情報を提供して、誰かが以前に遭遇した何かを見つけることができるようにしたかった.