Part 3 (Comms)
In this section of the tutorial, we will add communications to your pipeline, so that we can inspect what is going on.
Adding HTTP Communications
The standard method of communications between pipelines in Ark is
HTTP. You can add the HTTP stage to your pipeline by editing
the ${APP_ROOT}/tutorial/pipeline/tutorial_pipeline.cc
file.
Let’s change the C++ code to look like:
#include "tutorial/first_stage/first_stage.hh"
#include "ark/comms/stages/http_server_stage.hh"
#include "ark/main/main_offboard.hh"
int main(int argc, const char **argv)
{
ark::pipeline::Pipeline pipeline;
pipeline.add_stage<FirstStage>();
// Add the "HttpServerStage" to your pipeline.
pipeline.add_stage<ark::comms::HttpServerStage>();
return ark::main::execute_realtime_pipeline(argc, argv, std::move(pipeline));
}
Change your CMake to:
add_executable(tutorial_pipeline tutorial_pipeline.cc)
target_link_libraries(
tutorial_pipeline
PRIVATE first_stage ark::main_offboard ark::http_server_stage)
Compile and run:
./make.sh
./build/tutorial_pipeline
You should now see:
~/ark$ ./build/tutorial_pipeline
(2022-02-02 10:57:47.235) [warn] (context.cc:786) The publisher /my_strings (in stage FirstStage) was not connected to any subscribers.
(2022-02-02 10:57:47.236) [info] (http_server_stage.cc:874) HTTP Server is listening on "0.0.0.0:8080".
The server is up and listening on port 8080. In a future tutorial, we’ll go through how to configure the server to run on different ports.
In the meantime, open another terminal, and use ark-spy
to inspect the pipeline:
~/ark$ ./build/ark-spy
/debuglog
/my_strings
/scope_timing_reports
This lists the three channels that we have available. Let’s try to spy on the timing reports:
./build/ark-spy -c /scope_timing_reports
Timing reports are emitted every 5 seconds or so, so be patient. You should eventually see a large blob of JSON on the screen. Hit CTRL+C to exit.
Let’s try to spy on your channel next:
~/ark$ ./build/ark-spy -c /my_strings
FATAL: Couldn't fetch the schema for the requested channel. This typically means that that the type that flows on this channel is not serializable. The HTTP response code was 500.
As you can see, this fails, because the type we are publishing is not serializable! Let’s move on to Step 4 to learn about serialization.