Skip to content

Instantly share code, notes, and snippets.

@rootart
Created April 1, 2016 08:09
Show Gist options
  • Select an option

  • Save rootart/1d4888eb6a29fcc2f68bcf0af663be3e to your computer and use it in GitHub Desktop.

Select an option

Save rootart/1d4888eb6a29fcc2f68bcf0af663be3e to your computer and use it in GitHub Desktop.
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()
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()
@davidszotten
Copy link

hi. you probably want to use the nameko run command line tool to run your services, at least to start with. only looked briefly but the example above is missing eventlet.monkey_patch

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