私はØMQを使って運動しており、zguideを参照してcppzmqを使用して単純なサイト運営者/購読者を開発しました。以下のコードスニペットもご覧ください。データとメモリフットプリントを正常に公開して購読することもできます。これは分散型メッセージングシステムなので、プロジェクトで使用したいと思っています。ZeroMQでデータを暗号化するための提案
publisher.cpp
int main (int argc, char * argv[]) {
// Prepare our context and publisher
zmq::context_t context(1);
zmq::socket_t publisher(context, ZMQ_PUB);
std::string addr("tcp://*:");
addr += ((argc > 1) ? std::string(argv[1]) : "5563");
std::string tappend((argc > 2) ? std::string(argv[2]) : "");
publisher.bind(addr.c_str());
struct timeval timeofday;
for(unsigned int idx = 0; idx < Total_Topics; ++idx)
{
Topics.emplace(std::make_pair(idx, std::string("temperature/celsius" + tappend + std::to_string(idx))));
}
std::this_thread::sleep_for (std::chrono::seconds(2));
for(unsigned int NoOfTimes = 0; NoOfTimes < 20000; ++NoOfTimes)
{
for(unsigned int count = 0; count < Topics.size(); ++count)
{
{
Quote quote = {};
quote.ticker = "BHELL";
gettimeofday(&timeofday,NULL);
quote.timestampus = timeofday.tv_usec;
quote.timestamps = timeofday.tv_sec;
std::stringstream ss;
quote.value *= 0.1;
quote.data = std::to_string(NoOfTimes) + std::to_string(count);
ss << quote;
s_sendmore(publisher, Topics[count]);
std::cout << "Publish "<< Topics[count] << std::endl;
s_send(publisher, ss.str());
}
}
std::this_thread::sleep_for (std::chrono::seconds(8));
}
return 0;
}
subscriber.cpp
int main (int argc, char * argv[]) {
// Prepare our context and subscriber
zmq::context_t context(1);
zmq::socket_t subscriber (context, ZMQ_SUB);
std::string addr("tcp://localhost:");
addr += ((argc > 1) ? std::string(argv[1]) : "5563");
std::string tappend((argc > 2) ? std::string(argv[2]) : "");
subscriber.connect(addr.c_str());
struct timeval timeofday;
std::string topic("");
for(unsigned int idx = 0; idx < Total_Topics; ++idx)
{
topic = std::string("temperature/celsius" + tappend + std::to_string(idx));
subscriber.setsockopt(ZMQ_SUBSCRIBE, topic.c_str(), topic.length());
}
while(1)
{
{
Quote quote;
std::stringstream ss;
std::string address = s_recv (subscriber);
std::cout<<"Msg Rcvd" << std::endl;
std::cout<<"Topic: " << address << std::endl;
std::string contents = s_recv (subscriber);
ss << contents;
ss >> quote;
gettimeofday(&timeofday,NULL);
std::cout << "us diff " << (timeofday.tv_usec - quote.timestampus) << std::endl;
std::cout << "Sec diff " << (timeofday.tv_sec - quote.timestamps) << std::endl;
}
}
return 0;
}
今、私はzeroMQして使用する必要がありますどのセキュリティ技術知っていただきたいと思います。私はcurveZMQとczmqがあることを理解しています。しかし、どちらを使うべきかわからない。誰でも既にこれらのいずれかを使用しているか、ZeroMQセキュリティのために他のライブラリを持っています。お知らせ下さい。
CurveZMQはあなたが望むものです。 czmqは、ベースのZeroMQライブラリ(C++で書かれています)へのCインタフェースを提供します。それは暗号化を提供しません。 – colini
@コリーニ、それについていくつかの光を放つためにありがとう。私はzeroMQにかなり新しいです。私は今それを完全に理解している。 CurveZMQにはnode.jsバインディングがありますか?ありがとう – Panch