Giter Site home page Giter Site logo

Add akka-like messaging about micro HOT 14 CLOSED

prolic avatar prolic commented on June 5, 2024
Add akka-like messaging

from micro.

Comments (14)

codeliner avatar codeliner commented on June 5, 2024 3

Question is: The concept of Akka wouldn't work in PHP's shared nothing architecture, right?
So we would need something like amp or reactPHP to handle incoming requests in a non-blocking way and keep the PHP process alive and then pthreads for the Akka stuff. Am I right?

Or can we use ZeroMQ to create a lightweight link between a prooph/micro service (normal PHP process, global state is reset after request) and a process manager (long-running stateless PHP process)?

from micro.

bweston92 avatar bweston92 commented on June 5, 2024

How would these aggregates talk, remembering everything is eventually consistent?

from micro.

prolic avatar prolic commented on June 5, 2024

I don't know yet. Akka works with threads and locks them.

from micro.

max-voloshin avatar max-voloshin commented on June 5, 2024

I doubt we should implement Akka in PHP, but I am sure we can use core principles of Actor Model in PHP software.

Our team currently use in-house solution for background messaging processing with concurrency control (e.g. aggregate consumes only one message at the same time) and scheduling feature. We use PHP daemon process with child processes and DB for storing messages.

In the near future, we plan to rethink and summarize our experience via open source toolkit: REMBO (yeah, it's empty repo now, but you can "Watch" for updates :) ). Most likely we will optionally use mentioned AMP for better performance and scalability.

Draft:

$system = new ExampleSystem();
$message = new ExampleMessage();
$consumer = new ExampleConsumer();

$system->produce($message);

$system->produce(new ScheduleCommand($message, When::once(new DateTimeImmutable('2017-01-01'))));
$system->produce(new ScheduleCommand($message, When::after(3)->seconds()));
$system->produce(new ScheduleCommand($message, When::every(5)->minutes()));
$system->produce(new ScheduleCommand($message, When::every(10)->hours()->since(new DateTimeImmutable('2017-01-01'))));
$system->produce(new ScheduleCommand($message, When::every()->days()));

$system->produce(new DirectMessage($message, $consumer));

$system->produce(new ScheduleCommand(new DirectMessage($message, $consumer), When::after(10)->minutes()));
$system->produce(new ScheduleCommand(new DirectMessage($message, $consumer), When::every()->hours()));

In this case $consumer implements AddressableConsumer interface that allows using this consumer in DirectMessage. This will lead to consuming this message via this consumer in a background process. Bonus: we can rely on "one message at the same time" control.

P.S. BTW I think rembo and prooph will perfectly complement each other on DDD/Microservices field in the future.

from micro.

codeliner avatar codeliner commented on June 5, 2024

@max-voloshin Looks very interesting. Watch configured for REMBO ;)

but I am sure we can use core principles of Actor Model in PHP software.

I guess, I need to read more about the Actor Model. Anyone aware of a good blog post or something?

rembo and prooph will perfectly complement each other on DDD/Microservices field

👍

from micro.

max-voloshin avatar max-voloshin commented on June 5, 2024

I guess, I need to read more about the Actor Model. Anyone aware of a good blog post or something?

https://channel9.msdn.com/Shows/Going+Deep/Hewitt-Meijer-and-Szyperski-The-Actor-Model-everything-you-wanted-to-know-but-were-afraid-to-ask

from micro.

codeliner avatar codeliner commented on June 5, 2024

nice, thx 👍

from micro.

codeliner avatar codeliner commented on June 5, 2024

short update: I'm still in the process of learning and thinking more about the Actor Model.
Besides that @sandrokeil and me are playing with different ways to call other php processes.

We started with Symfony Process which simply uses exec under the hood.

But there are much better options of course. One of these options is the fast-cgi-client written by @hollodotme . Here is a very interesting block post: https://hollo.me/php/experimental-async-php-volume-2.html

We're trying to run an Actor insight a PHPFastCGI Daemon by @AndrewCarterUK

The Actor should run in an event loop (amp)

Now we want to test if we can send a message from one PHP process to this Actor with the help of the fast-cgi-client.
On the other end the PHPFastCGI Daemon would turn that message into a PSR-7 request and pass it to a handler (the mailbox of the Actor) which also runs in the amp event loop.
Once the message (PSR-7 request containing a prooph message in the body) is queued the Actor can pull that message from the queue, process it and create new messages which are again sent to an Actor via the fast-cgi-client (it supports async messaging of course)

from micro.

codeliner avatar codeliner commented on June 5, 2024

@max-voloshin

In this case $consumer implements AddressableConsumer interface that allows using this consumer in DirectMessage.

I'd be very interested how this works under the hood. Can you provide more details?

from micro.

max-voloshin avatar max-voloshin commented on June 5, 2024

I'd be very interested how this works under the hood. Can you provide more details?

@codeliner, looks like my previous comment was a bit premature, so it took some time to describe overall concept :) I would appreciate you read "Initial thoughts about Reliable Embedded Message Broker for PHP" and give feedback about it.

short update: I'm still in the process of learning and thinking more about the Actor Model.
Besides that @sandrokeil and me are playing with different ways to call other php processes.

Any update on your experiments?

@prolic, I noticed your comment in prooph/event-store#267 (comment):

I am plannig on providing an akka like actor to the php world. This will be highly experimental in the first development stage.

May you explain your expectations from this solutions? Do they match with rembo's description at some point?

@codeliner, @prolic it would be great if we had overlapping goals and expectation, so we could join our efforts.

from micro.

prolic avatar prolic commented on June 5, 2024

I am thinking about using an implementation of the gossip protocol in php and socket connections for communications across processes / servers. But there is nothing done yet, and we are working on releasing the new event-store v7 and related components, so any discussions about how, what, ... has to be delayed, until we have to time to address this again.

All I can say now, I have some plans, I know a lot of people think "you can't do this in PHP" - and I'll prove them wrong :-) I will have something in very early alpha stage maybe in six months. Until then - it's time to work on current prooph components.

from micro.

codeliner avatar codeliner commented on June 5, 2024

@max-voloshin very interesting blog post about Rembo. Looking forward to working code. With event sourcing we take a slightly different route. Our write model only produces messages/domain events (no application state) and the event store acts as a "inbox repository". the new projection features included in the upcoming event store v7 release can be used to pull messages from the event store and forward them to some workers (among other usage scenarios).
If you have a first open source version of Rembo available, please let me know and we think about integrations. In the meanwhile we need to focus on prooph components marketing. We want to increase visibility and therefor provide more how-tos about the things we already have.

So also no real updates on the Actor Model experiments. We had to stop them for now due to huge amount of other work on the desk. I'm still very interested in the topic but I do think that I need to focus on other topics first. I guess the actor model can become very complex to manage in a production system. For now I'll favor our new prooph/micro approach:
One php-fpm pool and a lightweight code base for one aggregate type, because one transaction should only be handled and should only effect one aggregate.
Then we'll use the event store like described above to asynchronously build read models and talk to other aggregates. That is a more or less simple set up and a powerful solution, too. We want to provide a management UI to make prooph/micro even more easy to use, but that is a different story.

from micro.

codeliner avatar codeliner commented on June 5, 2024

Just found kraken-php framework, which is actor-based and ships w/ all basic functionality that you need for event sourced actors (addressable containers, message channels, messagebox, supervision, ...)
I think kraken-php is experimental, but at least a demo of event sourced actors in PHP would be nice.

from micro.

prolic avatar prolic commented on June 5, 2024

For now this is out of scope of micro, closing therefore.

from micro.

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.