c - 使用 libevent 监控 couchbase 存储桶

标签 c events couchbase libevent

我正在尝试实现一个 C 应用程序,该应用程序将监视在 couchbase 远程集群上发生的写入/修改/新文档事件来自不同的应用程序。我现在熟悉 couchbase C SDK 和同步实例,但将其与 libevent 结合起来进行异步 I/O 时遇到了麻烦。

我读了 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.

这里有两个问题:我无法使用上面的代码进行连接,并且我不知道该往哪个方向开始接收事件。如果有人向我指出这个简单案例的链接或编码示例,这将解锁我。

最佳答案

确保您的库和应用程序使用相同的 libevent 版本。从存储库安装软件包时,您需要与其中使用的 libevent 版本保持一致(例如 ldd/usr/lib64/libcouchbase_libevent.so )。请记住,这必须具有相同的 ABI(例如,使用 libevent 的 2.0 -> 1.4 兼容层将不起作用,因为这两个版本包含不同的 ABI,并且使用与 1.4 链接的 libcouchbase_libevent.so 将在 2.0 下崩溃) .

有关完整的交流,请参阅对该问题的评论:)

关于c - 使用 libevent 监控 couchbase 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26262194/

相关文章:

C迭代结构数组

c - 如果用户在 C 中输入无效选项,则重复菜单并提示

jquery - 如何防止滑动触发点击?

asp.net - 您多久使用一次自定义事件?

c - 将字符串输入存储到C中的不同数组中

jquery - 拦截点击,执行一些操作,然后再次传播 "click"

Couchbase 使用 Keyset 分页对记录进行排序 - 丢失记录

apache-kafka - CDC(更改数据捕获)与 Couchbase

超过 2 个节点的 couchbase 社区版

使用外部库创建独立项目