mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +00:00
Update device configuration
- Move general config files out of example directory to fairmq/run. - Use FairMQProgOptions for MQ example 5. - Add SendPartAsync() for non-blocking send of a message part.
This commit is contained in:
parent
9625268c50
commit
7744d8bc91
|
@ -6,6 +6,8 @@
|
||||||
# copied verbatim in the file "LICENSE" #
|
# copied verbatim in the file "LICENSE" #
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/5-req-rep/ex5-req-rep.json ${CMAKE_BINARY_DIR}/bin/config/ex5-req-rep.json)
|
||||||
|
|
||||||
Set(INCLUDE_DIRECTORIES
|
Set(INCLUDE_DIRECTORIES
|
||||||
${CMAKE_SOURCE_DIR}/fairmq
|
${CMAKE_SOURCE_DIR}/fairmq
|
||||||
${CMAKE_SOURCE_DIR}/fairmq/devices
|
${CMAKE_SOURCE_DIR}/fairmq/devices
|
||||||
|
|
41
examples/MQ/5-req-rep/ex5-req-rep.json
Normal file
41
examples/MQ/5-req-rep/ex5-req-rep.json
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"fairMQOptions":
|
||||||
|
{
|
||||||
|
"device":
|
||||||
|
{
|
||||||
|
"id": "client",
|
||||||
|
"channel":
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"socket":
|
||||||
|
{
|
||||||
|
"type": "req",
|
||||||
|
"method": "connect",
|
||||||
|
"address": "tcp://localhost:5005",
|
||||||
|
"sndBufSize": "1000",
|
||||||
|
"rcvBufSize": "1000",
|
||||||
|
"rateLogging": "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"device":
|
||||||
|
{
|
||||||
|
"id": "server",
|
||||||
|
"channel":
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"socket":
|
||||||
|
{
|
||||||
|
"type": "rep",
|
||||||
|
"method": "bind",
|
||||||
|
"address": "tcp://*:5005",
|
||||||
|
"sndBufSize": "1000",
|
||||||
|
"rcvBufSize": "1000",
|
||||||
|
"rateLogging": "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include "boost/program_options.hpp"
|
#include "boost/program_options.hpp"
|
||||||
|
|
||||||
#include "FairMQLogger.h"
|
#include "FairMQLogger.h"
|
||||||
|
#include "FairMQParser.h"
|
||||||
|
#include "FairMQProgOptions.h"
|
||||||
#include "FairMQExample5Client.h"
|
#include "FairMQExample5Client.h"
|
||||||
|
|
||||||
#ifdef NANOMSG
|
#ifdef NANOMSG
|
||||||
|
@ -26,89 +28,66 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace boost::program_options;
|
||||||
typedef struct DeviceOptions
|
|
||||||
{
|
|
||||||
DeviceOptions() :
|
|
||||||
text() {}
|
|
||||||
|
|
||||||
string text;
|
|
||||||
} DeviceOptions_t;
|
|
||||||
|
|
||||||
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
|
||||||
{
|
|
||||||
if (_options == NULL)
|
|
||||||
throw runtime_error("Internal error: options' container is empty.");
|
|
||||||
|
|
||||||
namespace bpo = boost::program_options;
|
|
||||||
bpo::options_description desc("Options");
|
|
||||||
desc.add_options()
|
|
||||||
("text,t", bpo::value<string>()->default_value("something"), "Text to send to server")
|
|
||||||
("help", "Print help messages");
|
|
||||||
|
|
||||||
bpo::variables_map vm;
|
|
||||||
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
|
|
||||||
|
|
||||||
if (vm.count("help"))
|
|
||||||
{
|
|
||||||
LOG(INFO) << "EPN" << endl << desc;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bpo::notify(vm);
|
|
||||||
|
|
||||||
if ( vm.count("text") )
|
|
||||||
_options->text = vm["text"].as<string>();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
FairMQExample5Client client;
|
FairMQExample5Client client;
|
||||||
client.CatchSignals();
|
client.CatchSignals();
|
||||||
|
|
||||||
DeviceOptions_t options;
|
FairMQProgOptions config;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!parse_cmd_line(argc, argv, &options))
|
string text;
|
||||||
|
|
||||||
|
options_description clientOptions("Client options");
|
||||||
|
clientOptions.add_options()
|
||||||
|
("text", value<string>(&text)->default_value("Hello"), "Text to send out");
|
||||||
|
|
||||||
|
config.AddToCmdLineOptions(clientOptions);
|
||||||
|
|
||||||
|
if (config.ParseAll(argc, argv))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
string filename = config.GetValue<string>("config-json-file");
|
||||||
|
string id = config.GetValue<string>("id");
|
||||||
|
|
||||||
|
config.UserParser<FairMQParser::JSON>(filename, id);
|
||||||
|
|
||||||
|
client.fChannels = config.GetFairMQMap();
|
||||||
|
|
||||||
|
LOG(INFO) << "PID: " << getpid();
|
||||||
|
|
||||||
|
#ifdef NANOMSG
|
||||||
|
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
||||||
|
#else
|
||||||
|
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
client.SetTransport(transportFactory);
|
||||||
|
|
||||||
|
client.SetProperty(FairMQExample5Client::Id, id);
|
||||||
|
client.SetProperty(FairMQExample5Client::Text, text);
|
||||||
|
|
||||||
|
client.ChangeState("INIT_DEVICE");
|
||||||
|
client.WaitForEndOfState("INIT_DEVICE");
|
||||||
|
|
||||||
|
client.ChangeState("INIT_TASK");
|
||||||
|
client.WaitForEndOfState("INIT_TASK");
|
||||||
|
|
||||||
|
client.ChangeState("RUN");
|
||||||
|
client.InteractiveStateLoop();
|
||||||
}
|
}
|
||||||
catch (exception& e)
|
catch (exception& e)
|
||||||
{
|
{
|
||||||
LOG(ERROR) << e.what();
|
LOG(ERROR) << e.what();
|
||||||
|
LOG(INFO) << "Command line options are the following: ";
|
||||||
|
config.PrintHelp();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << "PID: " << getpid();
|
|
||||||
|
|
||||||
#ifdef NANOMSG
|
|
||||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
|
||||||
#else
|
|
||||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
client.SetTransport(transportFactory);
|
|
||||||
|
|
||||||
client.SetProperty(FairMQExample5Client::Id, "client");
|
|
||||||
client.SetProperty(FairMQExample5Client::Text, options.text);
|
|
||||||
client.SetProperty(FairMQExample5Client::NumIoThreads, 1);
|
|
||||||
|
|
||||||
FairMQChannel requestChannel("req", "connect", "tcp://localhost:5005");
|
|
||||||
requestChannel.UpdateSndBufSize(10000);
|
|
||||||
requestChannel.UpdateRcvBufSize(10000);
|
|
||||||
requestChannel.UpdateRateLogging(1);
|
|
||||||
|
|
||||||
client.fChannels["data"].push_back(requestChannel);
|
|
||||||
|
|
||||||
client.ChangeState("INIT_DEVICE");
|
|
||||||
client.WaitForEndOfState("INIT_DEVICE");
|
|
||||||
|
|
||||||
client.ChangeState("INIT_TASK");
|
|
||||||
client.WaitForEndOfState("INIT_TASK");
|
|
||||||
|
|
||||||
client.ChangeState("RUN");
|
|
||||||
client.InteractiveStateLoop();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,11 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "boost/program_options.hpp"
|
||||||
|
|
||||||
#include "FairMQLogger.h"
|
#include "FairMQLogger.h"
|
||||||
|
#include "FairMQParser.h"
|
||||||
|
#include "FairMQProgOptions.h"
|
||||||
#include "FairMQExample5Server.h"
|
#include "FairMQExample5Server.h"
|
||||||
|
|
||||||
#ifdef NANOMSG
|
#ifdef NANOMSG
|
||||||
|
@ -24,40 +28,57 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace boost::program_options;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
FairMQExample5Server server;
|
FairMQExample5Server server;
|
||||||
server.CatchSignals();
|
server.CatchSignals();
|
||||||
|
|
||||||
LOG(INFO) << "PID: " << getpid();
|
FairMQProgOptions config;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (config.ParseAll(argc, argv))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
string filename = config.GetValue<string>("config-json-file");
|
||||||
|
string id = config.GetValue<string>("id");
|
||||||
|
|
||||||
|
config.UserParser<FairMQParser::JSON>(filename, id);
|
||||||
|
|
||||||
|
server.fChannels = config.GetFairMQMap();
|
||||||
|
|
||||||
|
LOG(INFO) << "PID: " << getpid();
|
||||||
|
|
||||||
#ifdef NANOMSG
|
#ifdef NANOMSG
|
||||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
||||||
#else
|
#else
|
||||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
server.SetTransport(transportFactory);
|
server.SetTransport(transportFactory);
|
||||||
|
|
||||||
server.SetProperty(FairMQExample5Server::Id, "server");
|
server.SetProperty(FairMQExample5Server::Id, id);
|
||||||
server.SetProperty(FairMQExample5Server::NumIoThreads, 1);
|
|
||||||
|
|
||||||
FairMQChannel replyChannel("rep", "bind", "tcp://*:5005");
|
server.ChangeState("INIT_DEVICE");
|
||||||
replyChannel.UpdateSndBufSize(10000);
|
server.WaitForEndOfState("INIT_DEVICE");
|
||||||
replyChannel.UpdateRcvBufSize(10000);
|
|
||||||
replyChannel.UpdateRateLogging(1);
|
|
||||||
|
|
||||||
server.fChannels["data"].push_back(replyChannel);
|
server.ChangeState("INIT_TASK");
|
||||||
|
server.WaitForEndOfState("INIT_TASK");
|
||||||
|
|
||||||
server.ChangeState("INIT_DEVICE");
|
server.ChangeState("RUN");
|
||||||
server.WaitForEndOfState("INIT_DEVICE");
|
server.InteractiveStateLoop();
|
||||||
|
}
|
||||||
server.ChangeState("INIT_TASK");
|
catch (exception& e)
|
||||||
server.WaitForEndOfState("INIT_TASK");
|
{
|
||||||
|
LOG(ERROR) << e.what();
|
||||||
server.ChangeState("RUN");
|
LOG(INFO) << "Command line options are the following: ";
|
||||||
server.InteractiveStateLoop();
|
config.PrintHelp();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user