cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Cassandra Wiki] Update of "ScribeToCassandra" by mck
Date Tue, 04 Jan 2011 18:02:10 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for change notification.

The "ScribeToCassandra" page has been changed by mck.


New page:
Getting Scribe to write to Cassandra can be very easy by just implementing a custom scribe
Here's a super simple example written in java and using Hector.
It uses a column family according to the LogEntry's category, and puts the payload directly
into a column name "scribePayload".
class ScribeToCassandraService implements com.facebook.scribe.scribe.Iface {

    private static final String CLUSTER_NAME = "myCluster";
    private static final String HOST_PORT = "localhost:9160";
    private static final String KEYSPACE = "keyspace1";
    private static final String COLUMN = "scribePayload";

    public ResultCode Log(final List<LogEntry> logEntries) throws TException {

        Cluster cluster = HFactory.getOrCreateCluster(CLUSTER_NAME, HOST_PORT);
        Mutator<UUID> mutator = HFactory.createMutator(HFactory.createKeyspace(KEYSPACE,
cluster), UUIDSerializer.get());
        for (LogEntry logEntry : logEntries) {

                String payload = logEntry.getMessage();
                String category = msg.getCategory();

                HColumn<String,String> column = HFactory.createColumn(

                UUID uuid = UUID.fromString(UUIDGenerator.getInstance().generateTimeBasedUUID().toString());
                mutator.addInsertion(uuid, category, column);

            }catch(Exception je){
                // example catch code
                LOG.error("invalid LogEntry\n"
                        + "category=" + logEntry.getCategory()
                        + "\nmessage is\n" + logEntry.getMessage() + "\n",

        return ResultCode.OK;

View raw message