+ All Categories
Home > Technology > RestMQ - HTTP/Redis based Message Queue

RestMQ - HTTP/Redis based Message Queue

Date post: 11-Nov-2014
Category:
Upload: gleicon
View: 68,046 times
Download: 2 times
Share this document with a friend
Description:
Presentation from TDC 2010 - http://www.thedevelopersconference.com.br/tdc/2010/sp/trilha-nosql
Popular Tags:
25
RestMQ Redis based Message Queue
Transcript
Page 1: RestMQ - HTTP/Redis based Message Queue

RestMQ

Redis based Message Queue

Page 2: RestMQ - HTTP/Redis based Message Queue

WHAT !?

RestMQ - Message Queue based on Redis

Data manipulation: HTTP GET/POST/DELETE, COMET and WebSockets

No signaling or specific protocol (optional JSON protocol)

http://www.restmq.com/

Gleicon Moraeshttp://github.com/gleiconhttp://zenmachine.wordpress.comhttp://www.7co.cc

Page 3: RestMQ - HTTP/Redis based Message Queue

Key/Value storage

Think memcached, GET and SET operations

[key] = value

>> SET key meh>> GET keymeh

>> SET fucounter 0>> INCR fucounter1>> GET fucounter1

Page 4: RestMQ - HTTP/Redis based Message Queue

Redis

Key-Value databaseAtomic operationsSemi-persistent or persistent storagePublish/Subscription channelsDifferent Data types: Sets, Sorted Sets, Lists, Hashes

http://code.google.com/p/redis/http://github.com/antirez/redishttp://rediscookbook.org/

Page 5: RestMQ - HTTP/Redis based Message Queue

Redis

Data types

StringsListsSets and Ordered SetsHashesPublish/Subscribe channels

Page 6: RestMQ - HTTP/Redis based Message Queue

Redis

Things you can do:

CacheInverted indexesFast countersThrottle controlCooler stuff at Redis CookbookLoad Balancing

Things you can't do:

Search inside all values for a given string

Page 7: RestMQ - HTTP/Redis based Message Queue

Redis

Things you can't do:

- Search inside all values for a given key- Search inside all values for a given key- Search inside all values for a given key

Page 8: RestMQ - HTTP/Redis based Message Queue

Message Queues

Does everything really needs to be tightly coupled ?Order: first come, first servedTransactions: there is no transaction, just trackingJob SchedulingPublish/SubscribeMap/Reduce

Page 9: RestMQ - HTTP/Redis based Message Queue

Message Queues

SMTP: Oldest Message Queue aroundAvoid hitting your DB real time with MQReal time: Ratings, Voting and CommentsTwitterDo I need NoSQL or I really need to clean my mess ?

Page 10: RestMQ - HTTP/Redis based Message Queue

RestMQ - Endpoints Diagram

Page 11: RestMQ - HTTP/Redis based Message Queue

RestMQ - Messages

/q/<queue> : Queue handling (GET/POST/DELETE)

$ curl -X POST -d "value=foobar" http://localhost:8888/q/testqtestq:1

$ curl -X POST -d "value=foobar" http://localhost:8888/q/testqtestq:2

$ curl http://localhost:8888/q/testq { "count": 0, "value": "foobar", "key": "testq:1" }

Page 12: RestMQ - HTTP/Redis based Message Queue

RestMQ - Messages

/c/<queue> : Comet Endpoint

$ curl http://localhost:8888/c/testq (hangs until there is a message to be received)

/ws/<queue> : WebSocket Endpoint

Needs the proper javascript code

Page 13: RestMQ - HTTP/Redis based Message Queue

RestMQ - MessagesJSON Protocol inspired by Amazon SQSFirst prototype at http://jsonqueue.appspot.com

add

{ "cmd" : "add", "queue" : "testq", "value" : "abacab" }

del

{ "cmd" : "del", "queue" : "testq", "key" : "testq:31" }

get

{ "cmd" : "get", "queue" : "testq", }

take

{ "cmd" : "take", "queue" : "testq", }

Page 14: RestMQ - HTTP/Redis based Message Queue

RestMQ - Status

/stats/<queue> : Queue status $ curl http://localhost:8888/stats/test

{ "queue" : "test", "redis": "127.0.0.1:6379 - 10 connection(s)", "len": {"len": 1} }

/stats : Server status $ curl http://localhost:8888/stats/

{ "count": 4, "queues": [ "devops:queue", "test3:queue", "test:queue", "test2:queue"], "redis": "127.0.0.1:6379 - 10 connection(s)" }

Page 15: RestMQ - HTTP/Redis based Message Queue

RestMQ - Controls

/p/<queue> : Distribution Policy for COMET and WS

Round Robin a message for each consumer Broadcast a message to all consumers

/control/<queue> : Queue start/stop

Pause all COMET consumers (useful for job schedulers)

Page 16: RestMQ - HTTP/Redis based Message Queue

RestMQ - Data structure Diagram

Page 17: RestMQ - HTTP/Redis based Message Queue

RestMQ - Algorithm

Algorithm for pushing messages into a queue named 'testq'

SADD testq into a SET called queuesetINCR a per-queue UUID generator called testq:uuidSET testq:<<id>>, messageLPUSH testq:<<id>> in to a LIST named testq:queue

Works for new and existing queues. On-the-fly queue creation.

Page 18: RestMQ - HTTP/Redis based Message Queue

RestMQ - Algorithm

Algorithm for reading messages from a queue named 'testq'

RPOP a key from a LIST named testq:queueGET the value associated to this key

For non-destructive GET operations:

LINDEX -1 to get a key in testq:queue LISTINCR key:refcount +1GET the value stored for key

Page 19: RestMQ - HTTP/Redis based Message Queue

RestMQ - Implementation(the core functionality can be implemented on any language)

Main branch 'Enterprise Edition'

PythonTwistedCycloneRedis async client

Embedded version

Sinatra + Ruby Reduced endpoints (GET/POST)

Page 20: RestMQ - HTTP/Redis based Message Queue

RestMQ - Sinatra Implementationhttp://gist.github.com/524240

GET /q - List all queues

Page 21: RestMQ - HTTP/Redis based Message Queue

RestMQ - Sinatra Implementationhttp://gist.github.com/524240

GET /q/<queue> - Get a message from <queue>

Page 22: RestMQ - HTTP/Redis based Message Queue

RestMQ - Sinatra Implementationhttp://gist.github.com/524240

POST /q/<queue> - Insert a message in <queue>

Page 23: RestMQ - HTTP/Redis based Message Queue

RestMQ - Map/Reduce

Page 24: RestMQ - HTTP/Redis based Message Queue

Questions ?

Page 25: RestMQ - HTTP/Redis based Message Queue

Thanks


Recommended