Created
April 1, 2016 08:09
-
-
Save rootart/1d4888eb6a29fcc2f68bcf0af663be3e to your computer and use it in GitHub Desktop.
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 logging | |
| import sqlalchemy as sa | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from nameko.runners import ServiceRunner | |
| from nameko_sqlalchemy import DB_URIS_KEY | |
| from nameko_sqlalchemy import Session | |
| from nameko.rpc import rpc | |
| config = { | |
| DB_URIS_KEY: { | |
| 'beta:app': 'sqlite+pysqlite:///data.db', | |
| }, | |
| 'AMQP_URI': "amqp://guest:guest@localhost", | |
| } | |
| Base = declarative_base(name='app') | |
| class Build(Base): | |
| __tablename__ = 'build' | |
| id = sa.Column(sa.Integer, primary_key=True) | |
| build_number = sa.Column(sa.Integer, nullable=False) | |
| class BetaService(object): | |
| name = 'beta' | |
| session = Session(Base) | |
| @rpc | |
| def get(self): | |
| return self.session.query(Build).all() | |
| def main(): | |
| logging.basicConfig(level=logging.DEBUG) | |
| logger = logging.getLogger('') | |
| logger.setLevel(logging.DEBUG) | |
| runner = ServiceRunner(config) | |
| runner.add_service(BetaService) | |
| runner.start() | |
| try: | |
| runner.wait() | |
| except KeyboardInterrupt: | |
| runner.stop() | |
| if __name__ == '__main__': | |
| main() |
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
| from nameko_sqlalchemy import DB_URIS_KEY | |
| from nameko.standalone.rpc import ClusterRpcProxy | |
| config = { | |
| DB_URIS_KEY: { | |
| 'beta:app': 'sqlite+pysqlite:///data.db', | |
| }, | |
| 'AMQP_URI': "amqp://guest:guest@localhost", | |
| } | |
| def main(): | |
| with ClusterRpcProxy(config) as cluster_rpc: | |
| print(cluster_rpc.beta.get()) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi. you probably want to use the
nameko runcommand line tool to run your services, at least to start with. only looked briefly but the example above is missingeventlet.monkey_patch