This repository only demonstrates integration of symfony/redis-messenger
to Laravel
Please do not use this code in real projects, because it has a lot of dirty workarounds
Please fill free to give me a feedback
I used Laravel's Homestead to bootstrap application. So you can run this example by starting Vagrant container and connecting to it:
vagrant up
vagrant ssh
cd /vagrant
There are two commands for demonstrate this example
php artisan bus:receive
Will listen redis queue and dump read messages in console
The example output for test data:
PongHandler:
object(App\Bus\Messages\PingMessage)#772 (1) {
["payload":"App\Bus\Messages\Message":private]=>
array(1) {
["id"]=>
string(36) "6a2f15b0-c166-4863-a96e-b662901c9333"
}
}
BusMessageHandled Event
string(1) "0"
object(App\Bus\Messages\PingMessage)#772 (1) {
["payload":"App\Bus\Messages\Message":private]=>
array(1) {
["id"]=>
string(36) "6a2f15b0-c166-4863-a96e-b662901c9333"
}
}
PlainHandler:
object(App\Bus\Messages\CustomMessage)#24 (1) {
["payload":"App\Bus\Messages\Message":private]=>
array(1) {
["id"]=>
string(36) "6a2f15b0-c166-4863-a96e-b662901c9333"
}
}
BusMessageHandled Event
string(1) "1"
object(App\Bus\Messages\CustomMessage)#24 (1) {
["payload":"App\Bus\Messages\Message":private]=>
array(1) {
["id"]=>
string(36) "6a2f15b0-c166-4863-a96e-b662901c9333"
}
}
php artisan bus:dispatch
You can check the messages sent to Redis with the following command:
redis-cli monitor | grep XADD
The example of data gone to redis:
1606668667.252463 [0 [::1]:33480] "XADD" "queue" "*" "message" "s:162:\"{\"body\":\"{\\\"payload\\\":{\\\"id\\\":\\\"6a2f15b0-c166-4863-a96e-b662901c9333\\\"}}\",\"headers\":{\"type\":\"App\\\\Bus\\\\Messages\\\\PingMessage\",\"Content-Type\":\"application\\/json\"}}\";"
1606668667.253650 [0 [::1]:33482] "XADD" "queue-custom" "*" "message" "s:73:\"{\"body\":\"{\\\"id\\\":\\\"6a2f15b0-c166-4863-a96e-b662901c9333\\\"}\",\"headers\":[]}\";"
Will send messages in queue.
app\Bus\Serializers
- JSON serialization of messagesapp\Bus\Messages
- Messages to be sent in queueapp\Bus\Handlers
- Handlers to process messages received from queueapp\Bus\DispatcherPool
- The simple pool which helps send messages in different channelsapp\Events
- Events dispatched on success or failed message processingapp\Listeners
- Listeners of eventsapp\Providers\BusServiceProvider
- Service Provider which binds all components together
I have implemented two serializers:
TransportJsonSerializer
- default serializer got from symfony package, and tuned a bitTransportJsonCustomSerializer
- Custom serializer which could be deeply configured
If you want to communicate with components created using another frameworks or languages you should continue
the ideas of TransportJsonCustomSerializer
Unfortunately, symfony/redis-messenger
doesn't allow modify messages in queue on
any way you want.
Messages should contain body
and headers
fields.
So, if your vendor component send messages with another structure you will have some headache to receive them correctly