Created
March 12, 2015 15:13
-
-
Save mamachanko/54a6cea5787fd55608eb to your computer and use it in GitHub Desktop.
Señor Chatto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interfaces: | |
chatto: | |
class: chatto:Chatto | |
chatto_client: | |
class: chattoclient:ChattoClient |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run with