I am trying to integrate Faust with Django to publish the messages to Kafka. Here is the example in Faust repo: https://github.com/robinhood/faust/tree/master/examples/django
I modified it a bit, and created views to push data to Kafka via Faust.
from django.shortcuts import render
from asgiref.sync import async_to_sync
from accounts.agents import AccountRecord, add_account
async def send_data() -> None:
print("sending..data")
print(await add_account.ask(AccountRecord(name="tesst", score=10.9, active=False)))
def index(request):
async_to_sync(send_data)()
return render(request, "accounts/index.html")
But, I get this error now:
RuntimeError at / Task <Task pending name='Task-1' coro=<AsyncToSync.main_wrap() running at /Users/mysuer/.pyenv/versions/3.8.3/envs/faustdjango/lib/python3.8/site-packages/asgiref/sync.py:204> cb=[_run_until_complete_cb() at /Users/mysuer/.pyenv/versions/3.8.3/lib/python3.8/asyncio/base_events.py:184]> got Future attached to a different loop
I am running this Django app using development server. What am I doing wrong? Anyone? :)