Skip to content

Commit b09cecb

Browse files
committed
Add automatic reconnect support for STOMP producers.
1 parent dec04ce commit b09cecb

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎.gitignore‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ bin/jp.php
99
bin/php-parse
1010
bin/google-cloud-batch
1111
bin/thruway
12+
bin/phpstan.phar
13+
bin/var-dump-server
14+
bin/yaml-lint
1215
vendor
1316
var
1417
.php_cs
1518
.php_cs.cache
16-
composer.lock
19+
composer.lock

‎pkg/stomp/StompProducer.php‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Interop\Queue\Message;
1212
use Interop\Queue\Producer;
1313
use Stomp\Client;
14+
use Stomp\Exception\ConnectionException;
1415
use Stomp\Transport\Message as StompLibMessage;
1516

1617
class StompProducer implements Producer
@@ -39,7 +40,18 @@ public function send(Destination $destination, Message $message): void
3940

4041
$stompMessage = new StompLibMessage($message->getBody(), $headers);
4142

42-
$this->stomp->send($destination->getQueueName(), $stompMessage);
43+
try {
44+
$this->stomp->send($destination->getQueueName(), $stompMessage);
45+
} catch (ConnectionException $ex) {
46+
if (!$this->stomp->isConnected()) {
47+
throw $ex;
48+
}
49+
50+
$this->stomp->disconnect(true);
51+
$this->stomp->connect();
52+
53+
$this->stomp->send($destination->getQueueName(), $stompMessage);
54+
}
4355
}
4456

4557
/**

0 commit comments

Comments
 (0)