Repository navigation
Replies: 1 comment
|
There are two levels, depending on how strict your CDC needs to be. 1. Keystone hooks: writes that go through Keystone (GraphQL API, Admin UI, Every list has an
So a shared publisher plus one line per list gives you a change event stream: async function publishChange(listKey: string, { operation, item, originalItem }: any) {
await producer.send({ // kafkajs / amqplib / SQS client, whatever you use
topic: `keystone.${listKey}`,
messages: [{
key: String((item ?? originalItem).id),
value: JSON.stringify({ operation, before: originalItem ?? null, after: item ?? null }),
}],
})
}
export const lists = {
Post: list({
access: allowAll,
fields: { /* ... */ },
hooks: { afterOperation: args => publishChange('Post', args) },
}),
}What this doesn't give you:
2. Real CDC: capture at the database If you need every change with delivery guarantees, do it below Keystone. Keystone uses Prisma, so the DB is a normal Postgres/MySQL. Use Postgres logical replication ( A middle ground is an outbox table: in If this solves it, please mark it as the answer so others with the same problem can find it. |
Uh oh!
There was an error while loading. Please reload this page.
I'm integrating KeystoneJs in a wider project. I need to apply the Change data capture (CDC) pattern.
Basicly it's all about to react to any create, update or delete performed to the database and send a message about that operation on a topic or on a message queue.
Is there any idea?
All reactions