资源说明:
dependencies: it depends on libevent > 2.0, which can be found at http://www.monkey.org/~provos/libevent/. compilation: type make and compilation of the single takes place. linkage will produce a dynamic binary called libevent-longpolling. run: execute this generated binary. to check that everything runs smooth, do the following: - consume first: wget -v http://127.0.0.1:8888/consumer/first_queue - then produce: curl -H "Content-Type: text/plain" -d "hello world" http://127.0.0.1:8888/producer/first_queue usage: users may have two distinct roles: - consumer: it makes HTTP requests to libevent-longpolling to receive content generated by a producer - producer: it makes HTTP POST request to send messages to consumer A message consists in an opaque body and a content-type. Content-Type supplied by producer will be sent in response later sent to consumer. Long-polling term refers to the fact that requests done by consumer are blocked by libevent-longpolling as long as no message is available. When a message is sent by producer, consumer request is unblocked by responding to it. Binding between consumer and producer is called a topic and its value is part of the URI: - a consumer makes requests on /consumer/[topic] - a producer pushes bodies on /producer/[topic] Topic creation is implicit: if a consumer asks for messages on a non existing topic, this one will be created. The same holds for producers. A topic may be purged by making an HTTP request on /purge/[topic]. Bound TCP address is 0.0.0.0:8888, meaning that every IP address your machine holds will be usable to connect to libevent-longpolling. Interested readers can directly look at the code, it is less than 300 lines of clean C :p pros: - this kind of pubsub mecanism will pass through enterprise's proxies, no reversed TCP connection is needed - if a timeout occurs (either due to an intermediate element, either due to the consumer HTTP stack impletation), one just has to make the same request again known issues: - no special care has been taken regarding HTTP requests: GET or POST or whatever, no check is done - URL parsing is partly taken from libevent HTTP Request-URI parsing and done uncarefully using strstr. - really should implement connection close callback from libevent
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。