-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix - Add automatic reconnect support for STOMP producers #1099
Changes from 9 commits
b09cecb
bfd08b1
b4afec2
2a0545c
a439f00
cd3c765
905b3e8
327ca4d
36d4e01
2e1d06d
b46a945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,10 +38,15 @@ class StompContext implements Context | |
*/ | ||
private $stompFactory; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $transient; | ||
|
||
/** | ||
* @param BufferedStompClient|callable $stomp | ||
*/ | ||
public function __construct($stomp, string $extensionType) | ||
public function __construct($stomp, string $extensionType, bool $detectTransientConnections = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is where we default to "off". |
||
{ | ||
if ($stomp instanceof BufferedStompClient) { | ||
$this->stomp = $stomp; | ||
|
@@ -53,6 +58,7 @@ public function __construct($stomp, string $extensionType) | |
|
||
$this->extensionType = $extensionType; | ||
$this->useExchangePrefix = ExtensionType::RABBITMQ === $extensionType; | ||
$this->transient = $detectTransientConnections; | ||
} | ||
|
||
/** | ||
|
@@ -173,6 +179,8 @@ public function createConsumer(Destination $destination): Consumer | |
{ | ||
InvalidDestinationException::assertDestinationInstanceOf($destination, StompDestination::class); | ||
|
||
$this->transient = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As soon as the first consumer is created against a context, we convert to long-lived and disable all transient functionality so that queues with heartbeats don't lose their connections while heartbeating. |
||
|
||
return new StompConsumer($this->getStomp(), $destination); | ||
} | ||
|
||
|
@@ -181,6 +189,10 @@ public function createConsumer(Destination $destination): Consumer | |
*/ | ||
public function createProducer(): Producer | ||
{ | ||
if ($this->transient && $this->stomp) { | ||
$this->stomp->disconnect(); | ||
} | ||
|
||
return new StompProducer($this->getStomp()); | ||
} | ||
|
||
|
@@ -202,14 +214,20 @@ public function purgeQueue(Queue $queue): void | |
public function getStomp(): BufferedStompClient | ||
{ | ||
if (false == $this->stomp) { | ||
$stomp = call_user_func($this->stompFactory); | ||
if (false == $stomp instanceof BufferedStompClient) { | ||
throw new \LogicException(sprintf('The factory must return instance of BufferedStompClient. It returns %s', is_object($stomp) ? get_class($stomp) : gettype($stomp))); | ||
} | ||
|
||
$this->stomp = $stomp; | ||
$this->stomp = $this->createStomp(); | ||
} | ||
|
||
return $this->stomp; | ||
} | ||
|
||
private function createStomp(): BufferedStompClient | ||
{ | ||
$stomp = call_user_func($this->stompFactory); | ||
|
||
if (false == $stomp instanceof BufferedStompClient) { | ||
throw new \LogicException(sprintf('The factory must return instance of BufferedStompClient. It returns %s', is_object($stomp) ? get_class($stomp) : gettype($stomp))); | ||
} | ||
|
||
return $stomp; | ||
} | ||
Comment on lines
+223
to
+232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hope you don't mind, I moved this out. 😄 |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally I indent lines like
79
, but the code style suggested this, apologies!