Skip to content

Commit

Permalink
Make messages persistent by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Sep 27, 2021
1 parent 1e5a89a commit 3bc7113
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/EventSubscriber/StompHeaderEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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');
}

}

}

0 comments on commit 3bc7113

Please sign in to comment.