...
Code Block |
---|
|
<properties>
<sdk.version>1.1.3<4</sdk.version>
</properties> |
...
Code Block |
---|
language | java |
---|
linenumbers | true |
---|
|
// Generate RequestID and InvocationID which will be used when logging and in HTTP requests
final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create();
final CbsRequest request = CbsRequests.getConfiguration(diagnosticContext);
// Read necessary properties from the environment
final EnvProperties env = EnvProperties.fromEnvironment();
// Create the client and use it to get the configuration
CbsClientFactory.createCbsClient(env)
.flatMap(cbsClient -> cbsClient.get(diagnosticContextrequest))
.subscribe(
jsonObject -> {
// do a stuff with your JSON configuration using GSON API
final int port = Integer.parseInt(jsonObject.get("collector.listen_port").getAsString());
// ...
},
throwable -> {
logger.warn("Ooops", throwable);
}); |
...
Code Block |
---|
language | java |
---|
linenumbers | true |
---|
|
// Generate RequestID and InvocationID which will be used when logging and in HTTP requests
final RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create();
final CbsRequest request = CbsRequests.getConfiguration(diagnosticContext);
// Read necessary properties from the environment
final EnvProperties env = EnvProperties.fromEnvironment();
// Polling properties
final Duration initialDelay = Duration.ofSeconds(5);
final Duration period = Duration.ofMinutes(1);
// Create the client and use it to get the configuration
CbsClientFactory.createCbsClient(env)
.flatMapMany(cbsClient -> cbsClient.updates(diagnosticContextrequest, initialDelay, period))
.subscribe(
jsonObject -> {
// do a stuff with your JSON configuration using GSON API
final int port = Integer.parseInt(jsonObject.get("collector.listen_port").getAsString());
// ...
},
throwable -> {
logger.warn("Ooops", throwable);
}); |
The most significant change is in line 1314. We are using flatMapMany since we want to map one CbsClient to many JsonObject updates. After 5 seconds CbsClient will call CBS every minute. If the configuration has changed it will pass the JsonObject downstream - in our case consumer of JsonObject will be called.
...