AGENDA 1. Quick introduction round 2. Setting up the project skeleton, while I guide you through the example code 3. Presentation: Introduction to messenger-concepts 4. Task 1: Introduce synchronous message processing 5. Presentation: Transports for async processing 6. Task 2: Pick your challenge(s) 7. Questions
GOALS Have fun Learn about the Messenger component Just 3 hours won't make you an expert, but hopefully you: • have a feeling whether this component is useful to you • maybe you get interested in message-based architecture Feel free to ask questions at any time. If you have suggestions how I can better suit your learning style, please let me know and I will adjust
WHO AM I Denis Brumann Software Developer at SensioLabs Germany in Berlin Twitter: @dbrumann Email: [email protected] Personal Focus: • Migrating client's legacy projects Symfony experience: • started with 2.0 • currently using 3.4 in client project • for private projects I try to use latest version possible
CORE CONCEPTS Message Data Object containing all relevant data Message Bus Takes a message and delegates it to the right recipient Message Handler Takes a Message-object and handles it, i.e. processes it
ADVANCED CONCEPTS Envelope Wrapper for a Message and contextual info (stamps) Stamp Provides context to/from a Middleware Middleware Controls the behavior of the Message Bus
MESSAGE BUS interface MessageBusInterface { /** * Dispatches the given message. * * @param object|Envelope $message The message or the message * pre-wrapped in an envelope * @param StampInterface[] $stamps */ public function dispatch($message, array $stamps = []): Envelope; }
SENDING A MESSAGE class MyService { private $messageBus; public function __construct(MessageBusInterface $messageBus) { $this->messageBus = $messageBus; } public function doSomething(string $url) { $this->messageBus->dispatch(new TakeScreenshotMessage($url)); } }
TASK 1 • Install the Messenger component • Modify App\Registration\Registration::register() or the corresponding Controller-action App\Controller\RegistrationController::register() to use the Messenger instead • Create a Message-object (you can take the Form-object as a reference point) • Dispatch the Message using the MessageBus
TASK 1 • Install the Messenger component • Modify App\Registration\Registration::register() or the corresponding Controller-action App\Controller\RegistrationController::register() to use the Messenger instead • Create a Message-object (you can take the Form-object as a reference point) • Dispatch the Message using the MessageBus • Create a MessageHandler
PICK YOUR CHALLENGE(S) • Validating messages inside the MessageBus • Sending registration mails with Symfony Mailer (using async transport) • Creating an implicit workflow using many sync/async-handled messages • Adding capability to deal with failing messages • Looking into CQRS • Creating a CommandBus, (QueryBus), EventBus