CDAP Stream Client for Java

The Stream Client Java API is for managing Streams from Java applications.

Supported Actions

  • Create a Stream
  • Update TTL (time-to-live, in seconds) for an existing Stream
  • Retrieve the current Stream TTL (in seconds)
  • Truncate an existing Stream (the deletion of all events that were written to the Stream)
  • Write an event to an existing Stream


To build the Stream Client Java API jar, use:

mvn clean package


To use the Stream Client Java API, include this Maven dependency in your project's pom.xml file:



Creating a StreamClient

Create a StreamClient instance, specifying the fields host and port of the CDAP instance:

StreamClient streamClient = new RestStreamClient.Builder("localhost", 11015).build();

Optional configurations that can be set (and their default values):

  • ssl: false (set to true to use HTTPS protocol)
  • verifySSLCert: true (set to false to suspend certificate checks; this allows self-signed certificates to be used when SSL is true)
  • authClient: null (CDAP Authentication Client to interact with a secure CDAP instance)


StreamClient streamClient = new RestStreamClient.Builder("localhost", 11015)

Creating a Stream

Create a new Stream with the <stream-id> streamName:



  • The <stream-id> should only contain ASCII letters, digits and hyphens.
  • If the Stream already exists, no error is returned, and the existing Stream remains in place.

Creating a StreamWriter

Create a StreamWriter instance for writing events to the Stream streamName:

StreamWriter streamWriter = streamClient.createWriter("streamName");

Writing Stream Events

To write new events to the Stream, use the StreamWriter interface:

ListenableFuture<Void> future = streamWriter.write("New log event", Charsets.UTF_8);

Truncating a Stream

To delete all events that were written to the Stream streamName, use:


Update the Stream Time-to-Live (TTL)

Update TTL (in seconds) for the Stream streamName:

streamClient.setTTL("streamName", newTTL);

Get the Stream Time-to-Live (TTL)

Get the current TTL value (in seconds) for the Stream streamName:

long ttl = streamClient.getTTL("streamName");

Close the Clients

When you are finished, release all resources by calling these two methods:


Source Code Repository

Source code (and other resources) for this page are available at the CDAP Ingest Project GitHub repository.