stan.py
stan.py copied to clipboard
How to using with Django?
How to include nats with Django application?
I'm trying run in from wsgi
def get_wsgi_application():
django.setup(set_prefix=False)
run_messaging()
return WSGIHandler()
def run_messaging():
def start_loop(loop):
asyncio.set_event_loop(loop)
loop.run_until_complete(run(loop))
loop.run_forever()
new_loop = asyncio.new_event_loop()
t = Thread(target=start_loop, args=(new_loop,))
t.start()
async def run(loop):
async def vcm_calendar_create(msg):
print("[{}] Received a message on queue subscription: {}".format(msg.sequence, msg.data))
nc = NATS()
sc = STAN()
client_id = f'calendar-sub-{os.getpid()}'
await nc.connect(settings.FDLT_NATS_URL, token=settings.FDLT_NATS_TOKEN, io_loop=loop)
await sc.connect(settings.FDLT_NATS_STREAM_CLUSTER_ID, client_id, nats=nc)
await sc.subscribe(subject="vcm", queue='vcm.calendar.create', cb=vcm_calendar_create)
But handler vcm_calendar_create can't work with Django ORM
Can you write example how implement it?