Event listeners, also currently known as the worker Component are PHP classes that receive and process incoming messages dispatched from the front-end servers. These listeners will reside on the back-end application servers, and handle the resource intensive operations of the system.
Again, routing keys are a string comprised of three elements, separated by a comma. The first element is the package alias, the second any alias you wish for the listener, and the third is the method name within the PHP listener class. You can create a new listener by creating a new worker Component, and for example within terminal type:
``./apex create worker casino.games casino.games`
This will create a blank PHP class at /src/casino/worker/games.php which you can fill with any methods you
desire. For example, maybe you add a
Now that we have our listener in place, we can start dispatching messages to it from the views / front-end servers. For example:
Example -- Execute PHP upon user Registration
Again, you will need to consult the documentation of the packages you are developing with to know which routing keys they support. For another example, say we want to execute PHP code every time a new user is registered, which we can do via the "users.profile.created" routing key. First, create a new worker / listener, and in terminal type:
`./apex create worker casino:users users.profile~
This will create a blank PHP listener class at /src/casino/worker/users.php, and will begin receiving all
messages dispatched to the "users.profile.*" routing key. Within the PHP class, add a
That's it. Now every time a new user is registered, that above method will be executed.
Need a Professional?
Need development work by the creator of Apex? E-mail firstname.lastname@example.org for a free consultation.
Subscribe to the low traffic mailing list to stay updated on Apex.