我想實現一個C應用程序,將監視寫道:/修改/新文檔事件從不同的應用未來一個couchbase遠程羣集上發生的事情。我現在熟悉couchbase C SDK和同步實例,但是我很難將它與libevent結合用於異步I/O。監視couchbase桶的libevent
我讀couchbase libevent plugin documentation和external event loop integration example,但我無法掌握我怎麼會告訴我的event_base的是,例如:
監測有關這一桶這個文件,並給我一個回調時,它的修改
這是我做的,到目前爲止:
首先,我創造我libevent的IO選項
struct event_base *mEvbase = event_base_new();
lcb_t instance;
lcb_error_t err;
struct lcb_create_io_ops_st ciops;
lcb_io_opt_t ioops;
memset(&ciops, 0, sizeof(ciops));
ciops.v.v0.type = LCB_IO_OPS_LIBEVENT;
ciops.v.v0.cookie = mEvbase;
err = lcb_create_libevent_io_opts(0, &ioops, mEvbase);
if (err != LCB_SUCCESS) {
ERRORMSG0("Failed to create an IOOPS structure for libevent: %s\n", lcb_strerror(NULL, error));
}
,然後創建我的實例:
struct lcb_create_st create_options;
std::string host = std::string("couchbase://192.168.130.10/");
host.append(bucket);
const char password[] = "password";
create_options.version = 3;
create_options.v.v3.connstr = host.c_str();
create_options.v.v3.passwd = password;
create_options.v.v3.io = ioops;
//Creating a lcb instance
err = lcb_create(&instance, &create_options);
if (err != LCB_SUCCESS) {
die(NULL, "Couldn't create couchbase handler\n", err);
return;
}
/* Assign the handlers to be called for the operation types */
lcb_set_bootstrap_callback(instance, bootstrap_callback);
lcb_set_get_callback(instance, generic_get_callback);
lcb_set_store_callback(instance, generic_store_callback);
,然後我安排的連接。
//We now schedule a connection to the server
err = lcb_connect(instance);
if (err != LCB_SUCCESS) {
die(instance, "Couldn't schedule connection\n", err);
lcb_destroy(instance);
}
lcb_set_cookie(instance, mEvbase);
我用libcouchbase版本2.0.17,libevent的核心版本2.0.so.5.1.9和libevent的額外版本2.0.so.5.1.9。使用上面的代碼,我的實例無法連接到couchbase。我得到以下警告:
event_pending: event has no event_base set.
event_add: event has no event_base set.
所以兩個問題在這裏:我無法連接使用上面的代碼,我不知道去開始接收事件的方向。如果有人指向我的這個簡單案例的鏈接或代碼示例,將解除阻止我。
您將在修改項目時向服務器請求通知。不幸的是,目前SDK本身並不支持這個功能。但是,您可以看看TAP或DCP以滿足您的需求。請澄清,如果這不是你想要的。 – 2014-10-10 02:38:17
謝謝你的回答。你能否給我一個TAP或DCP的鏈接,因爲我不知道它是什麼,谷歌也不會幫忙。 – Starscream 2014-10-10 07:16:53
TAP和DCP是節點用來在彼此之間複製數據的內部協議。雖然這些是內部協議,但您仍可以使用它們。目前Java SDK有一個TAP API。 C SDK目前沒有用於TAP的接口。請參閱http://www.couchbase.com/autodocs/couchbase-java-client-1.1.4/com/couchbase/client/TapClient.html – 2014-10-10 18:28:17