Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
msgflo-cpp/examples/repeat.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
46 lines (36 sloc)
997 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |