2014-10-08 49 views
2

我想實現一個C應用程序,將監視寫道:/修改/新文檔事件從不同的應用未來一個couchbase遠程羣集上發生的事情。我現在熟悉couchbase C SDK和同步實例,但是我很難將它與libevent結合用於異步I/O。監視couchbase桶的libevent

我讀couchbase libevent plugin documentationexternal 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.17libevent的核心版本2.0.so.5.1.9libevent的額外版本2.0.so.5.1.9。使用上面的代碼,我的實例無法連接到couchbase。我得到以下警告:

event_pending: event has no event_base set. 
event_add: event has no event_base set. 

所以兩個問題在這裏:我無法連接使用上面的代碼,我不知道去開始接收事件的方向。如果有人指向我的這個簡單案例的鏈接或代碼示例,將解除阻止我。

+0

您將在修改項目時向服務器請求通知。不幸的是,目前SDK本身並不支持這個功能。但是,您可以看看TAP或DCP以滿足您的需求。請澄清,如果這不是你想要的。 – 2014-10-10 02:38:17

+0

謝謝你的回答。你能否給我一個TAP或DCP的鏈接,因爲我不知道它是什麼,谷歌也不會幫忙。 – Starscream 2014-10-10 07:16:53

+1

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

回答

2

確保您的應用程序庫使用相同的libevent版本。從存儲庫安裝軟件包時,需要使用其中使用的libevent版本(例如ldd /usr/lib64/libcouchbase_libevent.so)。請記住,這必須是相同的ABI(例如,使用libevent的2.0 - > 1.4 compat層將不起作用,因爲這兩個版本包含不同的ABI,並且使用鏈接到1.4的libcouchbase_libevent.so將在2.0下打破) 。

要了解完整的交流,請參閱對問題的評論:)