Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36d4e01

Browse files
committed
Allow the detection of transient connections to be configured.
1 parent 327ca4d commit 36d4e01

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

pkg/stomp/StompConnectionFactory.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ public function __construct($config = 'stomp:')
7474
*/
7575
public function createContext(): Context
7676
{
77-
if ($this->config['lazy']) {
78-
return new StompContext(
79-
function () { return $this->establishConnection(); },
80-
$this->config['target']
81-
);
82-
}
77+
$stomp = $this->config['lazy']
78+
? function () { return $this->establishConnection(); }
79+
: $this->establishConnection();
80+
81+
$target = $this->config['target'];
82+
$detectTransientConnections = (bool) $this->config['detect_transient_connections'];
8383

84-
return new StompContext($this->establishConnection(), $this->config['target']);
84+
return new StompContext($stomp, $target, $detectTransientConnections);
8585
}
8686

8787
private function establishConnection(): BufferedStompClient

pkg/stomp/StompContext.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ class StompContext implements Context
4545

4646
/**
4747
* @param BufferedStompClient|callable $stomp
48-
* @param mixed $transient
4948
*/
50-
public function __construct($stomp, string $extensionType, $transient = true)
49+
public function __construct($stomp, string $extensionType, bool $detectTransientConnections = false)
5150
{
5251
if ($stomp instanceof BufferedStompClient) {
5352
$this->stomp = $stomp;
@@ -59,7 +58,7 @@ public function __construct($stomp, string $extensionType, $transient = true)
5958

6059
$this->extensionType = $extensionType;
6160
$this->useExchangePrefix = ExtensionType::RABBITMQ === $extensionType;
62-
$this->transient = $transient;
61+
$this->transient = $detectTransientConnections;
6362
}
6463

6564
/**
@@ -190,7 +189,7 @@ public function createConsumer(Destination $destination): Consumer
190189
*/
191190
public function createProducer(): Producer
192191
{
193-
if ($this->transient && true == $this->stomp) {
192+
if ($this->transient && $this->stomp) {
194193
$this->stomp->disconnect();
195194
}
196195

0 commit comments

Comments
 (0)