Skip to content

Instantly share code, notes, and snippets.

@mamachanko
Created March 12, 2015 15:13
Show Gist options
  • Save mamachanko/54a6cea5787fd55608eb to your computer and use it in GitHub Desktop.
Save mamachanko/54a6cea5787fd55608eb to your computer and use it in GitHub Desktop.
Señor Chatto
registry:
class: lymph.discovery.zookeeper:ZookeeperServiceRegistry
hosts: zk
event_system:
class: lymph.events.kombu:KombuEventSystem
transport: amqp
hostname: rabbitmq
instances:
chatto:
command: lymph instance --config=conf/chatto.yml
import lymph
class Chatto(lymph.Interface):
def on_start(self):
super(Chatto, self).on_start()
self.users = set()
@lymph.rpc()
def echo(self, text='pokemon'):
return text*3
@lymph.event('chatto.register')
def register(self, event):
print('List of usernames:', self.users)
username = event.body['username']
self.users.add(username)
print('User registered:', username)
@lymph.event('chatto.unregister')
def unregister(self, event):
print('List of usernames:', self.users)
username = event.body['username']
try:
self.users.remove(username)
except KeyError:
print('User is not exists:', username)
return
print('User unregistered:', username)
interfaces:
chatto:
class: chatto:Chatto
chatto_client:
class: chattoclient:ChattoClient
import lymph
class ChattoClient(lymph.Interface):
def on_start(self):
super(ChattoClient, self).on_start()
self.emit('chatto.register', {'username': 'tester'})
def on_stop(self):
super(ChattoClient, self).on_stop()
self.emit('chatto.unregister', {'username': 'tester'})
@mamachanko
Copy link
Author

run with

PYTHONPATH=examples lymph node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment