Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Catalinul's avatar

Spatie Event Sourcing not working on Docker

Has anyone ever encountered a problem like this or has anyone any idea?

So when I test the same code from my docker environment, on Xampp, everything works just fine but when I try use Docker, suddenly, my Reactor is not working anymore, even though if I run "php artisan event-sourcing:list" I get the correct answer, the event that I created is assigned to that particular Reactor.

I am using Laravel 9 and a simple docker-compose with php 8.1. I also have a queue service that uses the database.

0 likes
2 replies
rodrigo.pedra's avatar

What does your reactor do? Can you share its code?

Maybe it is not the reactor that is not being run, it is the action you expect it to perform that is failing from Docker, such as sending an email.

Have you tried manually triggering the reactor's action (copying past to a dummy route), to ensure all its expected effects can run within a Docker container?

1 like
Catalinul's avatar
Catalinul
OP
Best Answer
Level 1

@rodrigo.pedra This may sound strange, but following the docs I had no good result, so I had to look into the source code and find out that the docs were "lying", my Reactor was expecting a StoredEvent object according to the docs, but the library was actually emitting my own event back with an additional metaData property.

So I was using an Aggregator, when you persist the event, basically, save it in database using's the AggreagatorRoot's method "persist" according to the docs, if I add to the method that I am using in my Reactor which is tied to my custom event, as a parameter, the StoredEvent, to have access to the stored event that was saved, I should have access to the stored event but it's not really true. The library is firing back my own custom event with the additional metaData that I needed.

The docs: "Persisting an aggregate root will write all newly recorded events to the database. The newly persisted events will get passed to all projectors and reactors."

Then it goes on showing an example with the "StoredEvent" being passed to a projector, but this was not the event that was being emitted, it was actually my custom event that. I said that maybe it's not working for the Reactor and tried a Projector, same thing, that "StoredEvent" was not there, the only event emitted was my custom even with additional metaData. I tried the example code and was not working.

And I had this config dispatch_events_from_aggregate_roots to true.

Please or to participate in this conversation.