Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to using with Django? #46

Open
ghost opened this issue Oct 21, 2020 · 0 comments
Open

How to using with Django? #46

ghost opened this issue Oct 21, 2020 · 0 comments

Comments

@ghost
Copy link

ghost commented Oct 21, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants