-
Notifications
You must be signed in to change notification settings - Fork 2
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
Simple transactional outbox #4
Comments
In case there are multiple repositories using the outbox pattern probably we should add a key to separate them otherwise it might use the wrong function.
|
Now the scheduledBy field in outbox collection is the hostname. We can concatenate hostname with something like contextName. Maybe we can add a new field and use both scheduledBy and contextName |
I would use a dedicated property in the document, that might be the name of the To discuss further the api interfaces of the lib here: #9 |
Today I wrote another Outbox class here on the issue branch. I introduced the aggregateName to differentiate multiple instances on the same host. For this milestone (0.1.0) to keep the outbox api closed to "messaging" concept. The outbox interface is
The OutboxEvent is
Maybe in the future we will discuss a more generic interface. |
I was thinking that probably os.hostname might be good for k8s but not in other environments where you might have multi processes on the same machine or in case physical hardware where hostname as not been customized. |
Yes I had thought of that. In case of two app that use ddd-toolkit lib on the same machine I think PID should be used. In this implementation, the hostname is used as the default value of the hostname argument of the Outbox class constructor. If you use ddd-toolkit in the cloud, you will use the default value (os.hostame), but if you want you can pass something else (like process.pid). Will it be easy to explain this clearly in the documentation? |
But if you go up and down pid changes. In k8s a restart probably the hostname is kept but at startup or shutdown all events are sent so it's not really useful restoring a previous used value. If we use a certainly unique value this mechanism can be transparent to the library user and it's a value under the library control. |
So you would put in the scheduledBy field a uuid generated for each instance of the outbox? Because then aggregateName becomes useless. Let's decide if it makes sense to combine the outbox instances in the same process (host in the case of k8s) |
aggregateName meaning is mapping data with code callback, the uuid could be the same per node but yes if each instance is in charge than one random uuid would be useful for both aims |
Is the uuid the same for every instance of the Outbox class in the same app? In any case the aggregateName is needed for the data-fn mapping. |
I might have a good idea.
What do you think @lucagiove? // cdc async iterator
for await (const change of this.activeChangeStream) {
console.log('change!');
await this.publishEvent((change as any).fullDocument);
}
private async publishEvent(outBoxModel: OutBoxModel) {
const { modifiedCount } = await this.collection.updateOne(
{ _id: outBoxModel._id },
{ $set: { status: 'processing' } },
);
if (modifiedCount !== 1) {
this.logger.log(`Already processing by another outbox`);
return;
}
try {
await this.publishEventFn(outBoxModel.event);
await this.collection.updateOne(
{ _id: outBoxModel._id },
{
$set: {
status: 'published',
publishedAt: new Date(),
},
},
);
} catch (e) {
this.logger.warn(`Failed publishEventFn with ${JSON.stringify(outBoxModel.event)}`);
}
} |
I would remove this from the first beta and keep repo, event bus and command bus |
No description provided.
The text was updated successfully, but these errors were encountered: