Java Ingestion Client

The StreamX Ingestion API Java Client allows developers to use the StreamX Ingestion API directly from their Java applications. This client enables to feed data into the StreamX by making HTTP requests by REST Ingestion Service.

How to add to the project

With Maven, add the following dependency to your pom.xml.

<dependency>
    <groupId>dev.streamx</groupId>
    <artifactId>ingestion-client</artifactId>
</dependency>

Usage

The Java Ingestion Client provides a StreamxClient as the main entry point for interacting with the REST Ingestion Service from a Java application. StreamxClient can be initialized with the restIngestionHost, which is the URL of the REST Ingestion Service.

StreamxClient client = StreamxClient.create(restIngestionHost);

To initialize a reusable publisher you must provide the 'channel' and associated data model class.

Publisher<Data> publisher = client.newPublisher(channel, Data.class);

The list of available channels and the schemas registered to StreamX can be found by querying the REST Ingestion Service /schema endpoint.

Publish data

Publish the data under specific dataKey.

publisher.publish(dataKey, data);

Unpublish data

Unpublish the data under specific dataKey

publisher.unpublish(dataKey);

Data Model Class

The REST Ingestion Service accepts data in Avro format, so effective data management requires to define @AvroGenerated data model classes.

Generating Data Model Classes from AVRO Schema Apache

AVRO provides a Maven plugin for generating data model classes from AVRO schema files.

<plugin>
    <groupId>org.apache.avro</groupId>
    <artifactId>avro-maven-plugin</artifactId>
</plugin>

Schema files could be retrieved from the REST Ingestion Service /schema endpoint.

Reusing Data Model Classes

You can reuse data model classes from your StreamX mesh services implementations. To achieve that you can copy these classes to your project codebase.

Remember to keep the same java packages structure as in services code base. The package name is a part of AVRO schema, and it is validated.

Configuration

The Java Ingestion Client offers several configuration options to meet specific needs.

Custom HTTP Requester Configuration

HttpRequester is an interface that allows for injecting a custom HTTP client implementation. If this is set, the custom Apache HTTP Client Configuration is ignored.

HttpRequester customHttpRequester = new CustomHttpRequester();
StreamxClientBuilder streamxClientBuilder = StreamxClient.builder(restIngestionHost)
    .setHttpRequester(customHttpRequester);
StreamxClient client = streamxClientBuilder.build();

Custom Apache HTTP Client Configuration

The default HttpRequester implementation uses Apache HTTP client. You can change the HTTP client by using StreamxClientBuilder. Default client is used when not provided.

CloseableHttpClient httpClient = HttpClients.custom().build();
StreamxClientBuilder streamxClientBuilder = StreamxClient.builder(restIngestionHost)
    .setApacheHttpClient(httpClient);
StreamxClient client = streamxClientBuilder.build();

Authentication Configuration

REST Ingestion Service can be secured with JWT Token. In that case authentication token must be passed to the StreamXClient.

StreamxClientBuilder streamxClientBuilder = StreamxClient.builder(restIngestionHost)
    .setAuthToken(token);
StreamxClient client = streamxClientBuilder.build();