aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/forward/AmqpClient.java7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/forward/AmqpClient.java b/src/main/java/org/traccar/forward/AmqpClient.java
index 361cfffee..8ac618f5c 100644
--- a/src/main/java/org/traccar/forward/AmqpClient.java
+++ b/src/main/java/org/traccar/forward/AmqpClient.java
@@ -47,6 +47,13 @@ public class AmqpClient {
Connection connection = factory.newConnection();
channel = connection.createChannel();
channel.exchangeDeclare(exchange, BuiltinExchangeType.TOPIC, true);
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try {
+ connection.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }));
} catch (IOException | TimeoutException e) {
throw new RuntimeException("Error while creating and configuring RabbitMQ channel", e);
}