GithubHelp home page GithubHelp logo

messenger's Introduction

Requirements

  1. Docker
  2. Java 8 JVN, http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  3. mvn 3, sorry I couldn't get this going smoothly with docker-compose :( (brew install mvn)

The idea is to use the scalability and fault tolarance of cassandra and make use of a eventlog that persist the immutable state of the message during its lifetime.

Setup:

  1. Build with mvn mvn clean install

  2. setup cassandra (this should boot upp everything, but im curently a docker noob): docker-compose up

When its up:

Login to cqlsh by running this commmand

docker-compose exec cassandra-node1 cqlsh -u cassandra -p cassandra

1c. Then run these:

CREATE KEYSPACE IF NOT EXISTS messenger WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '1' };

CREATE TABLE messenger.message_log (    
    uuid timeuuid,
    message_uuid timeuuid,
    channel text,        
    created timestamp,
    content text,
    operation text,
    PRIMARY KEY (channel, uuid)
) WITH CLUSTERING ORDER BY (uuid ASC);
CREATE TABLE messenger.message (            
    uuid timeuuid,
    log_uuid timeuuid,
    channel text,        
    created timestamp,
    content text,
    is_deleted boolean,
    PRIMARY KEY (channel, uuid)
) WITH CLUSTERING ORDER BY (uuid ASC);

done! exit the shell ctrl-c

  1. run the app java -jar target/messenger-jar-with-dependencies.jar

4a. create some messages post to /messages/:channel with a message param

curl -X POST "http://localhost:3030/messages/mrshish?message=hello!" curl -X POST "http://localhost:3030/messages/mrshish?message=bye!"

4b. get the messages log (max 100 at the time) curl -X GET "http://localhost:3030/messages/mrshish"

{
  "messageLog" : [ {
    "index" : "8cf0ee82-fa56-11e6-8768-d92f3d48d3f4",
    "messageUuid" : "8cf0c771-fa56-11e6-8768-2f1eb9365922",
    "channel" : "mrshish",
    "created" : "2017-02-24T06:00:32.011+0000",
    "message" : "hello!",
    "operation" : "CREATE"
  }, {
    "index" : "951a5154-fa56-11e6-8768-cd7ff848ed74",
    "messageUuid" : "951a5153-fa56-11e6-8768-05ead0c08a0f",
    "channel" : "mrshish",
    "created" : "2017-02-24T06:00:45.704+0000",
    "message" : "hello!",
    "operation" : "CREATE"
  } ],
  "lastLogIndex" : "951a5154-fa56-11e6-8768-cd7ff848ed74"
}

4c get message from index http://localhost:3030/messages/mrshish?lastLogIndex=2998ff2c-fa57-11e6-8768-0f36baf4bd45

4d get message from index, with limit http://localhost:3030/messages/mrshish?lastLogIndex=2998ff2c-fa57-11e6-8768-0f36baf4bd45&limit=10

4d delete one or more messages.

curl -X DELETE "http://localhost:3030/messages/mrshish?messageUuid=d281d89e-fa3e-11e6-a0b6-6937373f5faf&messageUuid=d39b37e0-fa3e-11e6-a0b6-974d8a5c51bb"

We never delete messages. We mark them deleted. The message log will display "create" event of the message, and the delete "event".

messenger's People

Contributors

mrshish avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.