Search…
Using Java SDK
Guide to start using Konduit-Serving with Java SDK
This quickstart article will show you to begin your project in the Java environment. Konduit-Serving provides Java SDK, a developer tool that enable you to write the code with more ease, effectiveness and efficiency. Let's start building and installing Konduit-Serving from the source and take a look to demonstrate the examples of Konduit-Serving in Java.

Prerequisites

You will need following prerequisites to follow along

Installation from Sources

The following section explains how to clone and build Konduit-Serving from sources. To build from source, follow the guide below:
Once you've installed the Konduit-Serving to your local maven repository, you can now include it in your build tool's dependencies. Follow the instructions below for an example of Konduit-Serving with Java SDK.

Java SDK

Let's look at the examples how to use Konduit-Serving in Java

Cloning Examlpe Repository

Let's clone the konduit-serving-examples repository:
1
$ git clone https://github.com/KonduitAI/konduit-serving-examples
Copied!
You'll see the following files in konduit-serving-examples:
1
konduit-serving-examples/
2
├── data
3
├── java
4
├── monitoring
5
├── notebooks
6
├── python
7
├── quickstart
8
├── README.md
9
├── utils
10
└── yaml
Copied!
You'll need to open the "java" file in IntelliJ as a project, and you'll find two examples under the ./src/main/java subfolder. Let's look at the examples of Konduit-Serving to create a configuration and deploy a server.

Example

Let’s start by defining the inference configuration and sequence pipeline that define the configuration of the server:
1
InferenceConfiguration inferenceConfiguration = new InferenceConfiguration();
2
3
SequencePipeline sequencePipeline = SequencePipeline
4
.builder()
5
.add(new LoggingStep().log(LoggingStep.Log.KEYS_AND_VALUES))
6
.build();
Copied!
The inference configuration should have a pipeline to deploy the server, include pipeline with:
1
inferenceConfiguration.pipeline(sequencePipeline);
2
3
System.out.format(inferenceConfiguration.toYaml());
Copied!
You'll see the printed server configuration as a YAML:
1
---
2
host: "localhost"
3
port: 0
4
use_ssl: false
5
protocol: "HTTP"
6
static_content_root: "static-content"
7
static_content_url: "/static-content"
8
static_content_index_page: "/index.html"
9
kafka_configuration:
10
start_http_server_for_kafka: true
11
http_kafka_host: "localhost"
12
http_kafka_port: 0
13
consumer_topic_name: "inference-in"
14
consumer_key_deserializer_class: "io.vertx.kafka.client.serialization.JsonObjectDeserializer"
15
consumer_value_deserializer_class: "io.vertx.kafka.client.serialization.JsonObjectDeserializer"
16
consumer_group_id: "konduit-serving-consumer-group"
17
consumer_auto_offset_reset: "earliest"
18
consumer_auto_commit: "true"
19
producer_topic_name: "inference-out"
20
producer_key_serializer_class: "io.vertx.kafka.client.serialization.JsonObjectSerializer"
21
producer_value_serializer_class: "io.vertx.kafka.client.serialization.JsonObjectSerializer"
22
producer_acks: "1"
23
mqtt_configuration: {}
24
custom_endpoints: []
25
pipeline:
26
steps:
27
- '@type': "LOGGING"
28
logLevel: "INFO"
29
log: "KEYS_AND_VALUES"
Copied!
Let's deploy the server by using DeplotKonduitServing.deploy() includes created inference configuration with the pipeline into the deployment:
1
DeployKonduitServing.deploy(
2
new VertxOptions(),
3
new DeploymentOptions(),
4
inferenceConfiguration,
5
handler -> {
6
if (handler.succeeded()) {
7
InferenceDeploymentResult inferenceDeploymentResult = handler.result();
8
int runningPort = inferenceDeploymentResult.getActualPort();
9
String deploymentId = inferenceDeploymentResult.getDeploymentId();
10
11
System.out.format("%nPort is %s and Deployment Id is %s.%n", runningPort, deploymentId);
12
13
try {
14
String result = Unirest.post(String.format("http://localhost:%s/predict", runningPort))
15
.header("Content-Type", "application/json")
16
.header("Accept", "application/json")
17
.body(new JSONObject().put("input_key", "input_value"))
18
.asString().getBody();
19
20
System.out.format("Result: %s%n", result);
21
22
System.exit(0);
23
} catch (UnirestException e) {
24
e.printStackTrace();
25
System.exit(1);
26
}
27
} else {
28
System.out.println(handler.cause().getMessage());
29
System.exit(1);
30
}
31
}
32
33
);
Copied!
The handler expression is a callback after a successful or failed server deployment which can be implemented inside the handler block, as shown:
1
Port is 38019 and Deployment Id is cc5e2081-81e4-4d3e-9734-3201af512641.
2
Result: {
3
"input_key" : "input_value"
4
}
5
6
Process finished with exit code 0
Copied!
Congratulation! You've deployed Konduit-Serving using Java SDK.
Last modified 6mo ago