Because most services and collectors deployed on DCAE platform relies on similar microservices a commmon Software Development Kit has been created. It contains utilities and clients which may be used when getting configuration from CBS, consuming messages from DMaaP, interacting with AAI, etc. SDK is written in Java.
NOTE For now only Config Binding Service client has reached a stable API level. More are expected to be done in Dublin.
NOTE This page is a work in progress.
Table of Contents |
---|
Artifacts
Current version
Code Block | ||
---|---|---|
| ||
<properties>
<sdk.version>1.1.2-SNAPSHOT</sdk.version>
</properties> |
Maven dependencies
Choose one or more depending on what you need.
Code Block | ||
---|---|---|
| ||
<dependencies>
<dependency>
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
<artifactId>cbs-client</artifactId>
<version>${sdk.version}</version>
</dependency>
<!-- more to go -->
</dependencies> |
Available APIs
cbs-client
- a Config Binding Service client
You can use CbsClientFactory to lookup for CBS in your application. Returned CbsClient can then be used to get a configuration, poll for configuration or poll for configuration changes.
Sample usage:
Code Block | ||
---|---|---|
| ||
// Generate RequestID and InvocationID which will be used when logging and in HTTP requests
RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create();
// 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(diagnosticContext))
.subscribe(jsonObject -> {
// do a stuff with your JSON configuration using GSON API
final int port = Integer.parseInt(jsonObject.get("collector.listen_port").getAsString());
// ...
}); |
Notes about reactive programming
Most of SDK APIs are using Project Reactor. which is one of available implementation of Reactive Streams (as well as Java 9 Flow). This way we support both high-performance, non-blocking asynchronous clients and old-school, thread-bound, blocking clients. We believe that using reactive programming can solve many cloud-specific problems for us - if used properly.
Handling streams of data—especially “live” data whose volume is not predetermined—requires special care in an asynchronous system. The most prominent issue is that resource consumption needs to be controlled such that a fast data source does not overwhelm the stream destination. Asynchrony is needed in order to enable the parallel use of computing resources, on collaborating network hosts or multiple CPU cores within a single machine.
The main goal of Reactive Streams is to govern the exchange of stream data across an asynchronous boundary—think passing elements on to another thread or thread-pool—while ensuring that the receiving side is not forced to buffer arbitrary amounts of data. In other words, back pressure is an integral part of this model in order to allow the queues which mediate between threads to be bounded. The benefits of asynchronous processing would be negated if the communication of back pressure were synchronous (see also the Reactive Manifesto), therefore care has to be taken to mandate fully non-blocking and asynchronous behavior of all aspects of a Reactive Streams implementation.
Before using DCAE SDK, please take a moment and read Project Reactor documentation and skim through methods available in Flux and Mono.
However if you are not concerned about performance you can always take a blue pill and go back to blocking world by means of block*
methodsClick here to see SDK architecture description.
Artifacts
Click here to see artifacts description.
Available APIs
Click here to see available APIs description.