远程控制

ZeroMQ分享-part1

2016-09-28  本文已影响416人  分享放大价值

1. ZeroMQ背景知识(version-4.2.0)

ZMQ(以下ZeroMQ简称ZMQ)是一个简单好用的、轻量级的消息组件,像框架一样的一个socket library。它的本质是个消息处理队列库,在BSD socket基础上做了一层封装,将网络通讯、进程通讯和线程通讯抽象为统一的接口,可在多个线程、内核和主机盒之间弹性伸缩。

2. ZMQ的几种模型

// Create a new ZMQ context
void *context = zmq_ctx_new();
// For client-server pattern
void *client_receiver = zmq_socket(context, ZMQ_CLIENT)
void *server_receiver = zmq_socket(context, ZMQ_SERVER)
// For publish-subscribe pattern
void *pub_receiver = zmq_socket(context, ZMQ_PUB)
void *xpub_receiver = zmq_socket(context, ZMQ_XPUB)
void *sub_receiver = zmq_socket(context, ZMQ_SUB)
void *xsub_receiver = zmq_socket(context, ZMQ_XSUB)
// For pipeline pattern
void *push_receiver = zmq_socket(context, ZMQ_PUSH)
void *pull_receiver = zmq_socket(context, ZMQ_PULL)
// For exclusive pair pattern
void *pair_receiver = zmq_socket(context, ZMQ_PAIR)
int rc;
rc = zmq_bind(pair_receiver, "inproc://#1")
assert(rc == 0);
rc = zmq_connect(pair_receiver, "inproc://#1")
assert(rc == 0);

// Native pattern
void *stream_receiver = zmq_socket(context, ZMQ_STREAM)

3. I/O模型

上一篇下一篇

猜你喜欢

热点阅读