Apache在c ++中点燃sqlfieldQuery的连续查询

时间:2017-06-28 09:41:36

标签: c++ apache ignite continuous

我们正在使用Apache Ignite SqlFieldQuery。连续查询是否支持SqlFieldQuery?我正在寻找与此相关的一些例子。

查询看起来像:

Cache<int32_t, std::string> cache = 
    ignite.GetOrCreateCache<int32_t, std::string>(CACHE_NAME);

std::string sql("INSERT INTO \"DG\".TestList (empid,name) values(11, 'name')");

SqlFieldsQuery orgQry(sql);
cache.Query(orgQry);

如何使用连续查询获取上述查询的通知?

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以使用简单的ContinuousQuery。像这样:

// Assuming your key type is int32_t
class Listener : public event::CacheEntryEventListener<int32_t, TestList>
{
public:
    virtual void OnEvent(const CacheEntryEvent<int32_t, TestList>* evts, uint32_t num)
    {
        // Simply printing events here. You can put your processing code here.
        for (uint32_t i = 0; i < num; ++i)
        {
            std::cout << "Queried entry [key=" << evts[i].GetKey()
                      << ", val=" << (evts[i].HasValue() ? evts[i].GetValue() : "<none>")
                      << ']' << std::endl;
        }
    }
};

int main()
{
    Ignite ignite = Ignition::Start(cfg);

    Cache<int32_t, TestList> cache = 
        ignite.GetOrCreateCache<int32_t, TestList>(CACHE_NAME);

    // Declaring listener.
    Listener<int32_t, TestList> listener;

    // Declaring continuous query.
    continuous::ContinuousQuery<int32_t, TestList> qry(MakeReference(listener));

    continuous::ContinuousQueryHandle<int32_t, TestList> handle = 
        cache.QueryContinuous(qry);

    std::string sql("INSERT INTO \"DG\".TestList (empid,name) values(11, 'name')");

    SqlFieldsQuery orgQry(sql);
    cache.Query(orgQry);

    // Waiting here to get notifications.
    std::cin.get();

    return 0;
}

我跳过了一些样板代码。您可以找到功能完整的代码示例here