Open ThisIsMissEm opened 4 months ago
Additionally we can then do something like the @adonisjs/core/services/router
package for registering consumers, like:
import consumers from '@neighbourhoodie/adonis-kafka/services/consumers'
const WebhookConsumer = () => import('#consumers/webhook_consumer')
const DownloadConsumer = () => import('#consumers/download_consumer')
consumers.group({ groupId: "webhook-service" })
.subscribe({ topic: 'messages' }, [WebhooksConsumer, 'handleWebhook'])
.subscribe({ topics: [ 'downloads' ] }, [DownloadsConsumer, 'handleDownload'])
.subscribe({ topics: [ 'downloads-retry' ] }, [DownloadsConsumer, 'handleDownloadRetry'])
consumers.start()
We could also remove the need for consumers.start()
by hooking into Service Provider's start()
hook
i.e., on server start, we automatically start the consumers that are registered (kinda like how you don't need to do a router.listen(port)
or something for HTTP).
Currently the patterns used in this plugin suggests sticking Kafka consumers in Adonis Controllers, which are typically for web requests, for better code separation, it'd be preferable to use a
consumers
directorySo,
app/controllers/kafka/webhooks_controller
becomesapp/consumers/webhooks
, as an example.I think this would only require minimal changes to implement and give a clearer separation of concerns.