Symfony Messenger 4.3

Symfony Messenger 4.3

Introduction to Symfony Messenger with a focus on the new features from the Symfony 4.3 release such as the new transports, retry strategies and handling failed messages.

6a1345d8e6dd15b2c78eff0c331963b1?s=128

Denis Brumann

July 11, 2019
Tweet

Transcript

  1. Symfony Messenger 4.3 Symfony User Group Köln Von Thomas Wolf,

    www.foto-tw.de, CC BY-SA 3.0 de, https://commons.wikimedia.org/w/index.php?curid=62082470
  2. Denis Brumann @dbrumann denis.brumann@sensiolabs.de

  3. Message Bus Handler

  4. Message

  5. None
  6. None
  7. None
  8. framework-agnostic data object

  9. Bus

  10. None
  11. None
  12. Handler

  13. None
  14. None
  15. framework-agnostic service reacting to a specific message

  16. None
  17. send receive

  18. Transport

  19. Sender Receiver

  20. None
  21. None
  22. None
  23. framework: messenger: transports: sync: 'sync://null' async: '%env(MESSENGER_TRANSPORT_DSN)%' routing: App\Message\RegisterUserMessage: 'async'

  24. framework: messenger: transports: sync: 'sync://null' async: 'amqp://root:s3cr3t@myhost/%2f/topic' routing: App\Message\RegisterUserMessage: 'async'

  25. None
  26. AMQP (RabbitMQ) Doctrine Redis

  27. None
  28. None
  29. None
  30. bin/console messenger:setup-transports

  31. send

  32. bin/console messenger:consume receive

  33. Usage: messenger:consume [options] [--] [<receivers>...] messenger:consume-messages Arguments: receivers Names of

    the receivers/transports to consume in order of priority [default: ["async"]] Options: -l, --limit=LIMIT Limit the number of received messages -m, --memory-limit=MEMORY-LIMIT The memory limit the worker can consume -t, --time-limit=TIME-LIMIT The time limit in seconds the worker can run --sleep=SLEEP Seconds to sleep before asking for new messages after no messages were found [default: 1] -b, --bus=BUS Name of the bus to which received messages should be dispatched (if not passed, bus is determine automatically.
  34. send receive

  35. Failing Messages

  36. framework: messenger: ... # default configuration retry_strategy: max_retries: 3 delay:

    1000 # delay for first retry multiplier: 2 # multiply delay with each try max_delay: 0 # service: null # id for custom RetryStrategy
  37. UnrecoverableMessageHandlingException

  38. framework: messenger: failure_transport: 'failed' transports: failed: 'doctrine://default?queue_name=failed' routing: ...

  39. bin/console messenger:failed:show bin/console messenger:failed:retry bin/console messenger:failed:remove

  40. None
  41. Middleware

  42. add_bus_name_stamp_middleware dispatch_after_current_bus send_message handle_message failed_message_processing_middleware

  43. add_bus_name_stamp_middleware dispatch_after_current_bus send_message handle_message failed_message_processing_middleware your middleware your middleware your

    middleware
  44. framework: messenger: buses: event_bus: default_middleware: 'allow_no_handlers' middleware: - 'messenger.middleware.validation'

  45. ReceivedStamp HandledStamp

  46. None
  47. None
  48. None
  49. Messages Buses Handlers & Transports

  50. Which messages are sent over which transport? config/packages/messenger.yaml framework :

    messenger : routing
  51. How to limit a transport to a bus? config/packages/messenger.yaml framework

    : messenger : routing
  52. Which Handler processes a message? Service Tag messenger.message_handler

  53. Which Handler processes a message? name: 'messenger.message_handler', handles: '*', #

    which message(s) to handle bus: 'event_bus', # restrict handler to specific bus method: 'handleEvent', # method to be called on handler priority: 1, # prioritize handler over others from_transport: 'async', # handle only received messages
  54. Which Handler processes a message?

  55. Which bus is injected into a service? config/packages/services.yaml Argument Binding

  56. Which bus is injected into a service? framework: messenger: default_bus:

    'first_bus' buses: first_bus: middleware: - 'messenger.middleware.validation' second_bus: ...
  57. Which bus is injected into a service? services: _defaults: bind:

    $firstBus: 'first_bus' $secondBus: 'second_bus'
  58. Which bus is injected into a service?

  59. None
  60. Usage examples https://github.com/dbrumann/invite-registration https://github.com/dbrumann/messenger-screenshot-demo https://github.com/dbrumann/dpc2019-workshop