在Cassandra中创建触发器的示例,这仅支持Java吗?

Aru*_*run 2 cassandra-2.1

想要检查Cassandra中的触发器功能。有人可以提供创建触发器的示例吗?

在此博客中, http://www.datastax.com/dev/blog/whats-new-in-cassandra-2-0-prototype-triggers-support

要创建触发器,您必须首先用实现该ITrigger接口的类构建一个jar,并将其放入每个节点上的triggers目录中,然后执行CQL3 CREATE TRIGGER请求以将触发器绑定到Cassandra表(或多个表)。

根据此信息,Cassandra中的触发器仅适用于基于Java的应用程序吗?

小智 5

卡桑德拉3.0

您可以使用它,它会将您插入的所有内容作为json

public class HelloWorld implements ITrigger
{
    private static final Logger logger = LoggerFactory.getLogger(HelloWorld.class);

    public Collection<Mutation> augment(Partition partition)
    {
        String tableName = partition.metadata().cfName;
        logger.info("Table: " + tableName);

        JSONObject obj = new JSONObject();
        obj.put("message_id", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));

        try {
            UnfilteredRowIterator it = partition.unfilteredIterator();
            while (it.hasNext()) {
                Unfiltered un = it.next();
                Clustering clt = (Clustering) un.clustering();  
                Iterator<Cell> cells = partition.getRow(clt).cells().iterator();
                Iterator<ColumnDefinition> columns = partition.getRow(clt).columns().iterator();

                while(columns.hasNext()){
                    ColumnDefinition columnDef = columns.next();
                    Cell cell = cells.next();
                    String data = new String(cell.value().array()); // If cell type is text
                    obj.put(columnDef.toString(), data);
                }
            }
        } catch (Exception e) {

        }
        logger.debug(obj.toString());

        return Collections.emptyList();
    }
}
Run Code Online (Sandbox Code Playgroud)