On this page, you can find instructions on how to build and run the cache example project on different platforms and get catalog and partition metadata, as well as partition data using HERE Data SDK for C++.
Before you run the example project, authorize to the HERE platform:
-
On the Apps & keys page, copy your application access key ID and access key secret.
For instructions on how to get the access key ID and access key secret, see the Register your application section in the Identity & Access Management Developer Guide.
-
In examples/main.cpp, replace the placeholders with your access key ID, access key secret, and Here Resource Name (HRN) of the catalog.
You can also specify these values using the command line options.
AccessKey access_key{"here.access.key.id", "here.access.key.secret"};
To build and run the example project on Linux:
-
Enable examples of the CMake targets.
mkdir build && cd build cmake -DOLP_SDK_BUILD_EXAMPLES=ON ..
-
In the build folder, build the example project.
cmake --build . --target dataservice-example -
Execute the example project.
./examples/dataservice-example --example read_stream --key_id "here.access.key.id" --key_secret "here.access.key.secret" --catalog "catalog"
-
(Optional) To run the example with other parameters, run the help command, and then select the needed parameter.
./examples/dataservice-example --help
After building and running the example project, you see the following information:
./dataservice-example– a catalog and layer description.read-stream-layer-example - Poll data - Success, messages size - 6– a success message that displays the size of data retrieved from the layer.
./dataservice-example --example read --key_id "here.access.key.id" --key_secret "here.access.key.secret" --catalog "catalog" --layer_id "layer_id" --type-of-subscription "subscription_type"
[INFO] read-stream-layer-example - Message data: size - 16
[INFO] read-stream-layer-example - No new messages is received
[INFO] read-stream-layer-example - Poll data - Success, messages size - 6You can read messages from a stream layer if you subscribe to it.
To get data from the stream layer:
-
Create the
OlpClientSettingsobject.For instructions, see Create platform client settings.
-
Create the
StreamLayerClientobject with the HERE Resource Name (HRN) of the catalog that contains the layer, layer ID, and platform client settings from step 1.olp::dataservice::read::StreamLayerClient client( client::HRN catalog, std::string layer_id, client::OlpClientSettings settings); -
Create the
SubscribeRequestobject with theserialorparallelsubscription type.-
If your application should read smaller volumes of data using a single subscription, use the
serialsubscription type. -
If your application should read large volumes of data in a parallel manner, use the
parallelsubscription type and subscription ID.
auto request = olp::dataservice::read::SubscribeRequest() .WithSubscriptionMode(olp::dataservice::read::SubscribeRequest::SubscriptionMode::kSerial));
-
-
Call the
Subscribemethod with theSubscribeRequestparameter.client::CancellableFuture<SubscribeResponse> Subscribe( SubscribeRequest request);You receive a subscription ID from the requested subscription to the selected layer.
-
Call the
Pollmethod.client::CancellableFuture<PollResponse> Poll();You get messages with the layer data and partition metadata. The
Pollmethod also commits the offsets, so you can continue polling new messages.If the data size is less than 1 MB, the data field is populated. If the data size is greater than 1 MB, you get a data handle that points to the object stored in the blob store.
-
If the data size is greater than 1 MB, call the
GetDatamethod with theMessagesinstance.client::CancellableFuture<DataResponse> GetData( const model::Message& message);
You get data from the requested partition.
If you want to stop message consumption, delete your subscription to a stream layer:
auto unsubscribe_response = stream_client.Unsubscribe().GetFuture().get();
if (unsubscribe_response.IsSuccessful()) {
// Successfully unsubscribed.
}