Streams

HStreamDB stores data in streams, and this page shows how to operate streams using Java SDK.

Prerequisites

  • Make sure you have HStreamDB running and accessible.
  • Include following import statements:
  1. import io.hstream.HStreamClient;
  2. import io.hstream.Stream;

Connect to a HStreamDB Instance

First, you need to connect to a HStreamDB instance and get a HStreamClient object.

  1. HStreamClient client = HStreamClient.builder().serviceUrl("SERVER_HOST:SERVER_PORT").build();

Get a List of Streams

You can get a list of the streams using the HStreamClient.listStreams() method:

  1. for(Stream stream: client.listStreams()) {
  2. System.out.println(stream.getStreamName());
  3. }

Create a New Stream

You can create a new stream with 3 replicators (default value) using the HStreamClient.createStream() method:

  1. client.createStream("test_stream");

You can also specify the number of replicators:

  1. client.createStream("test_stream", 5);

Delete a Stream

You can delete a stream using the HStreamClient.deleteStream() method:

  1. client.deleteStream("test_stream");