-
Notifications
You must be signed in to change notification settings - Fork 2
/
repeat.cpp
46 lines (36 loc) · 997 Bytes
/
repeat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <atomic>
#include <iostream>
#include <algorithm>
#include <chrono>
#include <thread>
#include "msgflo.h"
using namespace std;
atomic_bool run(true);
int main(int argc, char **argv)
{
std::string role = "repeat";
if (argc >= 2) {
role = argv[1];
}
msgflo::Definition def;
def.component = "C++Repeat";
def.label = "Repeats input on outport unchanged";
def.outports = {
{ "out", "any", "" }
};
def.role = role;
msgflo::EngineConfig config;
if (argc >= 3) {
config.url(argv[2]);
}
auto engine = msgflo::createEngine(config);
msgflo::Participant *participant = engine->registerParticipant(def, [&](msgflo::Message *msg) {
auto payload = msg->asJson();
std::cout << "Got message:" << endl << payload.dump() << std::endl;
participant->send("out", payload);
msg->ack();
});
std::cout << "C++Repeat started" << endl;
engine->launch();
return EXIT_SUCCESS;
}