[DOC] Update DCAE SDK doc for direct Kafka usage
[dcaegen2.git] / docs / sections / sdk / apis.rst
index a4937f7..f63ca4e 100644 (file)
@@ -6,8 +6,9 @@ Available APIs
 
 
 .. toctree::
-    :depth: 3
+    :maxdepth: 3
 
+.. _config_binding_service_sdk:
 
 cbs-client - a Config Binding Service client
 --------------------------------------------
@@ -112,7 +113,7 @@ crypt-password - an utility for BCrypt passwords
 ------------------------------------------------
 Library to generate and match cryptography password using BCrypt algorithm
 
-.. code-block:: java
+.. code-block:: bash
 
     java -jar crypt-password-${sdk.version}.jar password_to_crypt
 
@@ -120,8 +121,8 @@ Library to generate and match cryptography password using BCrypt algorithm
 
 Can be used like maven dependency to match generated password.
 
-dmaap-client - a DMaaP MR client
---------------------------------
+dmaap-client - a DMaaP MR client (upto version 1.9.3)
+-----------------------------------------------------
 After parsing CBS sink definitions you will get a Source or Sink value object. It can be then directly used to communicate with DMaaP Message Router REST API.
 
 Writing message publisher
@@ -168,6 +169,250 @@ Writing message subscriber
                     logger.warn("An unexpected error while receiving messages from DMaaP", ex);
                 });
 
+******************************************
+Configure timeout when talking to DMaaP-MR
+******************************************
+
+* publisher:
+
+.. code-block:: java
+
+   final MessageRouterPublishRequest request = ImmutableMessageRouterPublishRequest.builder()
+                .timeoutConfig(ImmutableDmaapTimeoutConfig.builder()
+                        .timeout(Duration.ofSeconds(2))
+                        .build())
+                .
+                .
+                .
+                .build();
+
+* subscriber:
+
+.. code-block:: java
+
+  final MessageRouterSubscribeRequest request = ImmutableMessageRouterSubscribeRequest.builder()
+                .timeoutConfig(ImmutableDmaapTimeoutConfig.builder()
+                        .timeout(Duration.ofSeconds(2))
+                        .build())
+                .
+                .
+                .
+                .build();
+
+The default timeout value (4 seconds) can be used:
+
+.. code-block:: java
+
+   ImmutableDmaapTimeoutConfig.builder().build()
+
+For timeout exception following message is return as failReason in DmaapResponse:
+
+.. code-block:: RST
+
+   408 Request Timeout
+   {"requestError":{"serviceException":{"messageId":"SVC0001","text":"Client timeout exception occurred, Error code is %1","variables":["408"]}}}
+
+*************************
+Configure retry mechanism
+*************************
+
+* publisher:
+
+.. code-block:: java
+
+       final MessageRouterPublisherConfig config = ImmutableMessageRouterPublisherConfig.builder()
+                .retryConfig(ImmutableDmaapRetryConfig.builder()
+                        .retryIntervalInSeconds(2)
+                        .retryCount(2)
+                        .build())
+                .
+                .
+                .
+                .build();
+       final MessageRouterPublisher publisher = DmaapClientFactory.createMessageRouterPublisher(config);
+
+* subscriber:
+
+.. code-block:: java
+
+    final MessageRouterSubscriberConfig config = ImmutableMessageRouterSubscriberConfig.builder()
+                .retryConfig(ImmutableDmaapRetryConfig.builder()
+                        .retryIntervalInSeconds(2)
+                        .retryCount(2)
+                        .build())
+                .
+                .
+                .
+                .build();
+    final MessageRouterSubscriber subscriber = DmaapClientFactory.createMessageRouterSubscriber(config);
+
+The default retry config (retryCount=3, retryIntervalInSeconds=1) can be used:
+
+.. code-block:: java
+
+    ImmutableDmaapRetryConfig.builder().build()
+
+Retry functionality works for:
+ - DMaaP MR HTTP response status codes: 404, 408, 413, 429, 500, 502, 503, 504
+ - Java Exception classes: ReadTimeoutException, ConnectException
+
+**************************************
+Configure custom persistent connection
+**************************************
+
+* publisher:
+
+.. code-block:: java
+
+       final MessageRouterPublisherConfig connectionPoolConfiguration = ImmutableMessageRouterPublisherConfig.builder()
+                 .connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
+                        .connectionPool(16)
+                        .maxIdleTime(10) //in seconds
+                        .maxLifeTime(20) //in seconds
+                        .build())
+                .build();
+       final MessageRouterPublisher publisher = DmaapClientFactory.createMessageRouterPublisher(connectionPoolConfiguration);
+
+* subscriber:
+
+.. code-block:: java
+
+    final MessageRouterSubscriberConfig connectionPoolConfiguration = ImmutableMessageRouterSubscriberConfig.builder()
+                    .connectionPoolConfig(ImmutableDmaapConnectionPoolConfig.builder()
+                        .connectionPool(16)
+                        .maxIdleTime(10) //in seconds
+                        .maxLifeTime(20) //in seconds
+                        .build())
+                .build();
+    final MessageRouterSubscriber subscriber = DmaapClientFactory.createMessageRouterSubscriber(connectionPoolConfiguration);
+
+The default custom persistent connection configuration (connectionPool=16, maxLifeTime=2147483647, maxIdleTime=2147483647) can be used:
+
+.. code-block:: java
+
+    ImmutableDmaapConnectionPoolConfig.builder().build()
+
+***************************************
+Configure request for authorized topics
+***************************************
+
+* publisher:
+
+.. code-block:: java
+
+    final MessageRouterSink sink = ImmutableMessageRouterSink.builder()
+                .aafCredentials(ImmutableAafCredentials.builder()
+                        .username("username")
+                        .password("password").build())
+                .
+                .
+                .
+                .build();
+
+    final MessageRouterPublishRequest request = ImmutableMessageRouterPublishRequest.builder()
+                .sinkDefinition(sink)
+                .
+                .
+                .
+                .build();
+
+* subscriber:
+
+.. code-block:: java
+
+    final MessageRouterSource sourceDefinition = ImmutableMessageRouterSource.builder()
+                .aafCredentials(ImmutableAafCredentials.builder()
+                        .username("username")
+                        .password("password")
+                        .build())
+                .
+                .
+                .
+                .build();
+
+    final MessageRouterSubscribeRequest request = ImmutableMessageRouterSubscribeRequest.builder()
+                .sourceDefinition(sourceDefinition)
+                .
+                .
+                .
+                .build();
+
+AAF Credentials are optional for subscribe/publish requests.
+Username and password are used for basic authentication header during sending HTTP request to dmaap-mr.
+
+dmaap-client - a Kafka client (For version 1.9.4)
+----------------------------------------------------
+
+Version 1.9.4 has tried to keep method signatures same as previous version so as to reduce impact on services using previous version of this library. You can create publisher and subscriber like it is done using previous version of this library (as shown above).
+
+Alternatively, version 1.9.4 of the library provides another constructor for creating them which is suggested to be used by new services.
+
+********************************
+Writing Publisher and subscriber
+********************************
+**Writing message publisher**
+
+.. code-block:: java
+
+    final MessageRouterPublisher publisher = new MessageRouterPublisherImpl();
+    final MessageRouterSink sinkDefinition; //... Sink definition obtained by parsing CBS response
+    final MessageRouterPublishRequest request = ImmutableMessageRouterPublishRequest.builder()
+            .sinkDefinition(sinkDefinition)
+            .build();
+
+**Writing message subscriber**
+
+.. code-block:: java
+
+    final MessageRouterPublisher subscriber = new MessageRouterSubscriberImpl();
+    final MessageRouterSource sourceDefinition; //... Source definition obtained by parsing CBS response
+    final MessageRouterSubscribeRequest request = ImmutableMessageRouterSubscribeRequest.builder()
+            .sourceDefinition(sourceDefinition)
+            .build();
+
+********************************
+Closing Publisher and subscriber
+********************************
+From version 1.9.4, the service needs to explicitly close the publisher and subscriber to avoid resource leakage. New close methods are introduced to do the same.
+
+**Closing message publisher**
+
+.. code-block:: java
+
+    publisher.close();
+
+**Closing message subscriber**
+
+.. code-block:: java
+
+    subscriber.close();
+
+******************************
+Environment variables required
+******************************
+If the service uses sdk library version 1.9.4, the service needs to ensure that two new environment variables are declared. These two environment variables are mandatory and are required to establish connection with kafka. They are as follows:
+
+.. code-block:: yaml
+
+    - name: BOOTSTRAP_SERVERS
+      value: onap-strimzi-kafka-bootstrap:9092
+    - name: JAAS_CONFIG
+         valueFrom:
+        secretKeyRef:
+          key: sasl.jaas.config
+          name: strimzi-kafka-admin
+
+The service can also provide optional standard Kafka properties as environment variables to override the default values used by the library. Such property names must be prefixed with string "kafka.". An example is given below:
+
+.. code-block:: yaml
+
+    # To override Kafka property "max.poll.interval.ms"
+    - name: kafka.max.poll.interval.ms
+      value: 35000
+    # To override Kafka property "heartbeat.interval.ms"
+    - name: kafka.heartbeat.interval.ms
+      value: 50000
+
 hvvesclient-producer - a reference Java implementation of High Volume VES Collector client
 ------------------------------------------------------------------------------------------
 This library is used in xNF simulator which helps us test HV VES Collector in CSIT tests. You may use it as a reference when implementing your code in non-JVM language or directly when using Java/Kotlin/etc.
@@ -207,7 +452,7 @@ Example JSON:
         "schemaReference": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml",
         "data":
         {
-            "exampleData: "SAMPLE_VALUE"
+            "exampleData": "SAMPLE_VALUE"
         }
     }
 
@@ -287,4 +532,4 @@ Errors in one of the mappings in schema-map - this mapping is not cached, a warn
 Errors in schemaRefPath returns errors:
 
 - If in the schemaRef path in the event we provide an url that refers to an existing schema, but the part after # refers to a non-existent part of it, then an error is thrown: IncorrectInternalFileReferenceException ("Schema reference refer to existing file, but internal reference (after #) is incorrect.") "
-- When in the schemaRef path in the event, we provide a url that refers to a non-existent mapping from public to localURL, a NoLocalReferenceException is thrown, which logs to the console: "Couldn't find mapping for public url. PublicURL: {}"
\ No newline at end of file
+- When in the schemaRef path in the event, we provide a url that refers to a non-existent mapping from public to localURL, a NoLocalReferenceException is thrown, which logs to the console: "Couldn't find mapping for public url. PublicURL: {}"