-
Notifications
You must be signed in to change notification settings - Fork 10
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
multiple queues #16
Comments
Hi and thanks for creating an issue and PR. But unfortunately, currently I'm not sure about the PR and the issue. So, here's the way you can achieve desired behavior right now:
from taskiq import async_shared_broker
broker1 = AioPikaBroker(queue_name="q1")
broker2 = AioPikaBroker(queue_name="q2")
@broker1.task
async def test() -> None:
print("nothing")
@broker2.task
async def test2() -> None:
print("nothing")
@async_shared_broker.task
async def test3() -> None:
print("nothing") But in this example
@broker1.task
async def target_task():
... You may call it with another broker like this: task = await target_task.kicker().with_broker(broker2).kiq() Adding queue names slow down message processing and I'm wondering how it can be useful in different scenarios. Can you please provide examples where it would be useful? |
For example, if I have background tasks of different durations and types, I can put tasks of different durations into different queues, and tasks of different categories into different queues.
This can be done by defining different brokers, but the management and use may be confusing. For example, if I need 5 queues, then I have to define 5 brokers, and I need to execute it 5 times when starting through the command line taskiq worker1:broker |
Different durations for tasks should not be a problem, since we execute our tasks in async way. Even if the function is sync, we use threadPool executor to make it async. If you're really want this functionality, probably I would suggest you to inherit from the AioPikaBroker and get queue name from task labels. Then you'll be able to define tasks exactly as in your example. I have to ask @taskiq-python/core-team about this feature, because currently I'm not sure into implementing it. |
This is an optional feature. If the user add_queue, multiple queues can be used, and there is almost no intrusion. |
After playing a bit more, and looking at taskiq_aio_pika/broker.py, I saw that declaring the brokers with an exchange name, did the trick: repo_process_broker = AioPikaBroker(
env.message_broker_url,
queue_name="repo_updates_queue",
exchange_name="repo_updates_exchange",
).with_result_backend(
RedisAsyncResultBackend(env.result_backend_url)
) :) |
Like this, I just give a simple example, or there may be other more elegant ways to create multiple queues.
The text was updated successfully, but these errors were encountered: