From 76aad0a9eed55edb3b89ac00b9d2610e9a3e0330 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 23 Jun 2021 16:27:12 -0300 Subject: [PATCH] Make messages persistent by default. --- src/EventSubscriber/StompHeaderEventSubscriber.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/EventSubscriber/StompHeaderEventSubscriber.php b/src/EventSubscriber/StompHeaderEventSubscriber.php index 47792efd2..c846e4a1f 100644 --- a/src/EventSubscriber/StompHeaderEventSubscriber.php +++ b/src/EventSubscriber/StompHeaderEventSubscriber.php @@ -37,15 +37,16 @@ public function __construct( */ public static function getSubscribedEvents() { return [ - StompHeaderEventInterface::EVENT_NAME => ['baseAuth', -100], + StompHeaderEventInterface::EVENT_NAME => ['baseHeaders', -100], ]; } /** - * Event callback; generate and add base authorization header if none is set. + * Event callback; generate and add base/default headers if not set. */ - public function baseAuth(StompHeaderEventInterface $stomp_event) { + public function baseHeaders(StompHeaderEventInterface $stomp_event) { $headers = $stomp_event->getHeaders(); + if (!$headers->has('Authorization')) { $token = $this->auth->generateToken(); if (empty($token)) { @@ -58,6 +59,13 @@ public function baseAuth(StompHeaderEventInterface $stomp_event) { } } + // In ActiveMQ, STOMP messages are not persistent by default; however, we + // would like them to persist, by default... make it so, unless something + // else has already set the header. + if (!$headers->has('persistent')) { + $headers->set('persistent', 'true'); + } + } }