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:
Alexey Rybalchenko 2015-11-11 11:06:11 +01:00
parent 9625268c50
commit 7744d8bc91
4 changed files with 130 additions and 87 deletions

View File

@ -6,6 +6,8 @@
# 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
${CMAKE_SOURCE_DIR}/fairmq
${CMAKE_SOURCE_DIR}/fairmq/devices

View 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"
}
}
}
}
}

View File

@ -17,6 +17,8 @@
#include "boost/program_options.hpp"
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
#include "FairMQExample5Client.h"
#ifdef NANOMSG
@ -26,59 +28,36 @@
#endif
using namespace std;
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;
}
using namespace boost::program_options;
int main(int argc, char** argv)
{
FairMQExample5Client client;
client.CatchSignals();
DeviceOptions_t options;
FairMQProgOptions config;
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;
}
catch (exception& e)
{
LOG(ERROR) << e.what();
return 1;
}
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();
@ -90,16 +69,8 @@ int main(int argc, char** argv)
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.SetProperty(FairMQExample5Client::Id, id);
client.SetProperty(FairMQExample5Client::Text, text);
client.ChangeState("INIT_DEVICE");
client.WaitForEndOfState("INIT_DEVICE");
@ -109,6 +80,14 @@ int main(int argc, char** argv)
client.ChangeState("RUN");
client.InteractiveStateLoop();
}
catch (exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Command line options are the following: ";
config.PrintHelp();
return 1;
}
return 0;
}

View File

@ -14,7 +14,11 @@
#include <iostream>
#include "boost/program_options.hpp"
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
#include "FairMQExample5Server.h"
#ifdef NANOMSG
@ -24,12 +28,29 @@
#endif
using namespace std;
using namespace boost::program_options;
int main(int argc, char** argv)
{
FairMQExample5Server server;
server.CatchSignals();
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
@ -40,15 +61,7 @@ int main(int argc, char** argv)
server.SetTransport(transportFactory);
server.SetProperty(FairMQExample5Server::Id, "server");
server.SetProperty(FairMQExample5Server::NumIoThreads, 1);
FairMQChannel replyChannel("rep", "bind", "tcp://*:5005");
replyChannel.UpdateSndBufSize(10000);
replyChannel.UpdateRcvBufSize(10000);
replyChannel.UpdateRateLogging(1);
server.fChannels["data"].push_back(replyChannel);
server.SetProperty(FairMQExample5Server::Id, id);
server.ChangeState("INIT_DEVICE");
server.WaitForEndOfState("INIT_DEVICE");
@ -58,6 +71,14 @@ int main(int argc, char** argv)
server.ChangeState("RUN");
server.InteractiveStateLoop();
}
catch (exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Command line options are the following: ";
config.PrintHelp();
return 1;
}
return 0;
}