Giter Club home page Giter Club logo

Comments (8)

codeliner avatar codeliner commented on June 11, 2024

interesting approach and I agree that a custom uuid generator could be useful.
But I'm not sure if we should solve it this way. It feels a bit hacky, because events are immutable and should have a uuid at the moment they are created. Also changing the behavior of DomainMessage::init() would be a BC break because one could rely on the generation of the UUID. That's the purpose of method: If information is not provided in another way the defaults kick in.

So I think the solution can work but we should not include it in the core. DomainMessage explicitly allows that one can override the init method and tweak it. That would be my preferred way to add the functionality if needed. A short example in the docs would be nice, tough.

@prolic your thoughts?
@Xerkus Is that ok for you?

from event-sourcing.

Xerkus avatar Xerkus commented on June 11, 2024

@codeliner I agree that it should not be used by default. It is a decision for the event implementers. However, I think following would be useful in the core:

  • Introduce interface for event.
  • Add support for interface in extractors.
  • Make sure core is using uuid getter and not property directly, eg in toArray()
  • May be trait for the interface that would in addition move uuid fallback generation to uuid getter and remove from init()
  • docs

That is if this approach is sensible at all. I can't think of a use case for event uuid in the aggregate at this time but I might be missing something.

from event-sourcing.

Xerkus avatar Xerkus commented on June 11, 2024

To clarify about immutability: in the code example I provided existence of uuid is explicitly checked and results in a noop if one is set exactly for that reason: to maintain immutability contract.

Also, I think event interface would belong here, together with extractors, not in common.

from event-sourcing.

codeliner avatar codeliner commented on June 11, 2024

Sounds like a good plan. I need to think about it and let's see what @prolic says about it.

One thing that bothers me: It feels complex or too much. Do you know what I mean? Instead of providing one solution the user has to decide now. We don't touch the default, ok. But more classes, more opportunities and maybe more confusion than necessary. Not sure, maybe I need to see it in action first. Do you want to provide a PR even without definit OK?

from event-sourcing.

Xerkus avatar Xerkus commented on June 11, 2024

It feels complex or too much.

Yeah, there is that. Plus uuid optimisations are usually needed way down the line, when most of the stuff is already there and working.

Do you want to provide a PR even without definit OK?

Probably not until august.

from event-sourcing.

fritz-gerneth avatar fritz-gerneth commented on June 11, 2024

The problems I see with setting the IDs so late are:

  • Either inconsistent with how commands / queries have their ID generated or this would need to be changed everywhere
  • The entity dispatching the event/command/query has no access to the respective ID. For events this might not be an issue, for commands & queries this is (correlation id).
  • To pass back the generated ID back to the one publishing the event/command/query the storage would need to return the new events, through the (possibly distributed) message bus.
  • This would at least life on the message bus, not the event store itself. Not all events are AggregateChanged events
  • (DDD) Events should always be in a valid state. They should protect their invariants to always only allow valid states. Not entirely sure though if the event ID should be seen as part of this invariant yet.

Imho, if you need a custom event ID it should be provided on event creation (so set it explicitly there by whomever creates the event). If implemented, I think this should go to the message bus instead. Still the issue remains to return the ID to the one submitting it (for correlation tracking ... ).

from event-sourcing.

prolic avatar prolic commented on June 11, 2024

I think the ID is part of the event / query / command. Therefore the ID should not be added lately by some magic that's hidden somewhere else.
Actually we have an ID interface, it's this: https://github.com/ramsey/uuid/blob/master/src/UuidInterface.php. I know, this is not part of our library but "only" a dependency, but that doesn't change much. If you want to use prooph with a custom uuid implementation, go ahead and implement ramseys's uuid interface (build a bridge, proxy methods, whatever). It's the same amount of work as implementing "our" ID interface.
We have an interface for messages, you you are completely free to use any uuid implementation and even add the ID late if you want to.
I don't see the real benefit in accepting this change, but maybe I am missing something?

from event-sourcing.

Xerkus avatar Xerkus commented on June 11, 2024

There is one case I didn't account for here: cloning event without uuid will result in different values when it is finally created on access.
Implementing lazy decorator factory using interface from ramsey lib is the only valid approach.
And on translator side it is better to implement translator decorator as well.
There is nothing to be done in prooph.

from event-sourcing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.