Publish data to a stream layer

You can create a queue that streams data to data consumers in real time using a stream layer.

To publish data to the stream layer:

  1. Create the OlpClientSettings object.

    For instructions, see Create platform client settings.

  2. Create the StreamLayerClientSettings object.

    auto stream_client_settings = olp::dataservice::write::StreamLayerClientSettings{};
  3. Create the StreamLayerClient object with the HERE Resource Name (HRN) of the catalog that contains the layer, the stream layer client settings from step 2, and the platform client settings from step 1.

    auto client = olp::dataservice::write::StreamLayerClient(
    olp::client::HRN{kCatalogHRN}, stream_client_settings, client_settings);
  4. Create the PublishDataRequest object with the data that you want to publish and layer ID.

    auto request = PublishDataRequest().WithData(buffer).WithLayerId(kLayer);
  5. Call the PublishData method with the DataRequest parameter.

    auto futureResponse = client.PublishData(request);
  6. Wait for the PublishDataResponse future.

    auto response = futureResponse.GetFuture().get();

The PublishDataResponse object holds details of the completed operation and is used to determine operation success and access resultant data:

  • IsSuccessful() – if the operation is successful, returns true. Otherwise, returns false.
  • GetResult()– if the operation is successful, returns the following resultant data: olp::dataservice::write::PublishDataResult
  • GetError() – contains error information as a result of an error in the olp::client::ApiError object.
if (response.IsSuccessful()) {
    auto response_result = response.GetResult();
    // Handle success
} else {
    auto api_error = response.GetError();
    // Handle fail

results matching ""

    No results matching ""