- 安装zeromq
$ wget http://www.zeromq.org/local--files/area:download/zeromq-2.0.6.tar.gz $ tar -xzf zeromq-2.0.6.tar.gz $ cd zeromq-2.0.6 $ ./configure --prefix=/home/app/zeromq $ make $ sudo make install // 重建so文件链接 $ sudo ln -s /home/app/zeromq/lib/libzmq.so.0.0.0 /usr/lib/libzmq.so.0 $ sudo ln -s /home/app/zeromq/lib/libzmq.so.0.0.0 /usr/lib/libzmq.so
- 测试zeromq
// client.c #include#include #include #include "/home/app/zeromq/include/zmq.h" int main () { int rc; void *ctx, *s; zmq_msg_t query, resultset; const char *query_string, *resultset_string = "OK"; /* Initialise 0MQ context, requesting a single application thread and a single I/O thread */ ctx = zmq_init (1, 1, 0); assert (ctx); /* Create a ZMQ_REP socket to receive requests and send replies */ s = zmq_socket (ctx, ZMQ_REP); assert (s); /* Bind to the TCP transport and port 5555 on the 'lo' interface */ rc = zmq_bind (s, "tcp://lo:5555"); assert (rc == 0); while (1) { /* Allocate an empty message to receive a query into */ rc = zmq_msg_init (&query); assert (rc == 0); /* Receive a message, blocks until one is available */ rc = zmq_recv (s, &query, 0); assert (rc == 0); /* Process the query */ query_string = (const char *)zmq_msg_data (&query); printf ("Received query: '%s'\n", query_string); zmq_msg_close (&query); /* Allocate a response message and fill in an example response */ rc = zmq_msg_init_size (&resultset, strlen (resultset_string) + 1); assert (rc == 0); memcpy (zmq_msg_data (&resultset), resultset_string, strlen (resultset_string) + 1); /* Send back our canned response */ rc = zmq_send (s, &resultset, 0); assert (rc == 0); zmq_msg_close (&resultset); } }
// server.cpp #include#include "/home/app/zeromq/include/zmq.hpp" int main () { try { // Initialise 0MQ context with one application and one I/O thread zmq::context_t ctx (1, 1); // Create a ZMQ_REQ socket to send requests and receive replies zmq::socket_t s (ctx, ZMQ_REQ); // Connect it to port 5555 on localhost using the TCP transport s.connect ("tcp://localhost:5555"); // Construct an example zmq::message_t with our query const char *query_string = "SELECT * FROM mytable"; zmq::message_t query (strlen (query_string) + 1); memcpy (query.data (), query_string, strlen (query_string) + 1); // Send the query s.send (query); // Receive and display the result zmq::message_t resultset; s.recv (&resultset); const char *resultset_string = (const char *)resultset.data (); printf ("Received response: '%s'\n", resultset_string); } catch (std::exception &e) { // 0MQ throws standard exceptions just like any other C++ API printf ("An error occurred: %s\n", e.what()); return 1; } return 0; }
// 编译 $ gcc `pkg-config --libs --cflags /home/app/zeromq/lib/pkgconfig/libzmq.pc` -o server server.c $ g++ `pkg-config --libs --cflags /home/app/zeromq/lib/pkgconfig/libzmq.pc` -o client client.cpp
注意:将so链接到usr/lib下 测试程序才运行成功!
- 安装java扩展不成功
configure.in:3: error: Autoconf version 2.61 or higher is required $ autoreconf --version autoreconf (GNU Autoconf) 2.59
没有时间细弄了 下次有时间再试吧 准备看下 activemq去

六月 17th, 2010 on 14:01
哇~ 技术博客啊~
订阅了~ 有时间学学PHP~
七月 16th, 2010 on 10:58
没用过,貌似很复杂。