Skip to content
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

Merged
merged 11 commits into from
Oct 8, 2020
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ bin/jp.php
bin/php-parse
bin/google-cloud-batch
bin/thruway
bin/phpstan.phar
bin/var-dump-server
bin/yaml-lint
vendor
var
.php_cs
.php_cs.cache
composer.lock
composer.lock
14 changes: 13 additions & 1 deletion pkg/stomp/StompProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Interop\Queue\Message;
use Interop\Queue\Producer;
use Stomp\Client;
use Stomp\Exception\ConnectionException;
use Stomp\Transport\Message as StompLibMessage;

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

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

$this->stomp->send($destination->getQueueName(), $stompMessage);
try {
$this->stomp->send($destination->getQueueName(), $stompMessage);
} catch (ConnectionException $ex) {
if (!$this->stomp->isConnected()) {
atrauzzi marked this conversation as resolved.
Show resolved Hide resolved
throw $ex;
}

$this->stomp->disconnect(true);
$this->stomp->connect();

$this->stomp->send($destination->getQueueName(), $stompMessage);
}
}

/**
Expand Down