RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
soa/logger/publish_output.cc
00001 /* publish_output.cc
00002    Jeremy Barnes, 29 May 2011
00003    Copyright (c) 2011 Datacratic.  All rights reserved.
00004 
00005 */
00006 
00007 #include "publish_output.h"
00008 
00009 
00010 using namespace std;
00011 
00012 
00013 namespace Datacratic {
00014 
00015 /*****************************************************************************/
00016 /* PUBLISH OUTPUT                                                            */
00017 /*****************************************************************************/
00018 
00019 PublishOutput::
00020 PublishOutput()
00021     : context(new zmq::context_t(1)),
00022       sock(*context, ZMQ_PUB)
00023 {
00024 }
00025 
00026 PublishOutput::
00027 PublishOutput(zmq::context_t & context)
00028     : context(ML::make_unowned_std_sp(context)),
00029       sock(context, ZMQ_PUB)
00030 {
00031 }
00032 
00033 PublishOutput::
00034 PublishOutput(std::shared_ptr<zmq::context_t> context)
00035     : context(context),
00036       sock(*context, ZMQ_PUB)
00037 {
00038 }
00039 
00040 PublishOutput::
00041 ~PublishOutput()
00042 {
00043 }
00044 
00045 void
00046 PublishOutput::
00047 bind(const std::string & uri)
00048 {
00049     //cerr << "publishing to " << uri << endl;
00050     sock.bind(uri.c_str());
00051 }
00052 
00053 void
00054 PublishOutput::
00055 logMessage(const std::string & channel,
00056            const std::string & message)
00057 {
00058     sendMesg(sock, channel, ZMQ_SNDMORE);
00059     sendMesg(sock, message, 0);
00060 }
00061 
00062 void
00063 PublishOutput::
00064 close()
00065 {
00066     int res = zmq_close(sock);
00067     if (res == -1)
00068         throw ML::Exception("zmq_close: %s", zmq_strerror(zmq_errno()));
00069 }
00070 
00071 } // namespace Datacratic
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator