» Explain the concepts of distributed systems » Explain the client and server » Explain how to write a client » Help you write a client » Experiment Thursday, June 28, 12
‘in’ tube, publishes to IRC from ‘out’ tube » Client subscribes to ‘in’ tube, publishes to ‘out’ tube » Redis is used as the pubsub middle man Thursday, June 28, 12
& sends messages to redis » Other thread listens to redis and pipes incoming messages to IRC » Otherwise, very simple (about 30 lines of Python) Thursday, June 28, 12
json from irc import IRCBot, run_bot from gevent import monkey monkey.patch_all() r = redis.StrictRedis(host='localhost', port=6379, db=0) Thursday, June 28, 12
inter-team communication » Any process can easily send messages to IRC in a few lines of code » Deploys » Updates » Errors » Monitoring Thursday, June 28, 12
‘data’ attribute has ‘to’ and ‘message’ keys; these are the meat of the message Send function def send(to, message): r.publish('out', json.dumps({ 'version': 1, 'type': 'privmsg', 'data': { 'to': to, 'message': message, } })) Thursday, June 28, 12
in: •Read the ‘data’ attribute as json •Print out a debug message with the pieces of data that we care about Receive function pubsub = r.pubsub() pubsub.subscribe('in') for msg in pubsub.listen(): data = json.loads(msg['data'])['data'] print "Got %s in %s from %s" % (data['message'], data['channel'], data['sender']) Thursday, June 28, 12
commands •Generally commands start with ‘!’, but don’t have to Do work if data['message'] == "hello": send(data['channel'], "Hello %s" % data['sender']) elif data['message'] == '!woot': send(data['channel'],"Indeed!") else: send(data['channel'],"Wat") Thursday, June 28, 12
IRC server » It has redis & a ZenIRCBot instance running » You just need to connect a client to redis » Connect the test client, get that working, then build your own Thursday, June 28, 12
in the channel » It will greet the person who said hi, along with saying its hostname » If this example works, you should see your hostname in the flood of output :) Thursday, June 28, 12
» WIRELESS: OSBbridge Network » http://192.168.30.35:8000 » To run this you should just need the redis client library » (sudo) easy_install redis » host = ‘192.168.30.35’ Thursday, June 28, 12