Route tasks to queues
You’ll split work into emails, reports and default queues, route tasks there without
touching call sites, and run a worker group per queue.
Prerequisites
Section titled “Prerequisites”- An app shared by producers and workers.
1. Add a Router
Section titled “1. Add a Router”import 'package:gisila_queue/gisila_queue.dart';
final router = Router() ..route('emails.*', queue: 'emails') ..routeMatching(RegExp(r'^reports\.(daily|monthly)$'), queue: 'reports');
final app = GisilaQueue.redis(namespace: 'shop', router: router);Rules are checked in order; the first match wins. Globs are anchored and only * is
special.
2. Or set a default queue on the task
Section titled “2. Or set a default queue on the task”app.task<void>('thumbnails.render', renderThumbnail, queue: 'cpu');The task default applies only where the task is registered in the producing process, and only when the router doesn’t match.
3. Override per call
Section titled “3. Override per call”await sendEmail.applyAsync(args: [userId], queue: 'emails-priority');An explicit queue: beats everything. Order: call, router, task default,
GisilaQueue.defaultQueue ('default').
4. Run workers per queue
Section titled “4. Run workers per queue”dart run bin/worker.dart --namespace=shop --queues=emails --concurrency=32dart run bin/worker.dart --namespace=shop --queues=reports --concurrency=2dart run bin/worker.dart --namespace=shop --queues=default,emails,reports --concurrency=8The last worker drains default first and helps with the others when default is empty.
5. Pause a queue during an incident
Section titled “5. Pause a queue during an incident”With a control channel (on by default in GisilaQueue.redis and WorkerCli):
await app.controlChannel.publish(const ControlMessage.pause('emails'));// ... fix the mail provider ...await app.controlChannel.publish(const ControlMessage.resume('emails'));Messages keep accumulating on the paused queue and run after resume.
Verify it works
Section titled “Verify it works”print(router.resolve('emails.welcome')); // emailsprint(router.resolve('reports.daily')); // reportsprint(router.resolve('reports.weekly')); // null → task default or 'default'dart run gisila_queue:gisila_queue inspect --namespace=shop --queues=default,emails,reports