diff options
author | Rodolfo Silva <contato@rodolfosilva.com> | 2023-08-07 12:05:06 -0300 |
---|---|---|
committer | Rodolfo Silva <contato@rodolfosilva.com> | 2023-08-07 12:05:06 -0300 |
commit | ac2ca17894da7fd43432c63056f6abef4a7a611b (patch) | |
tree | 1f1d1de3f7c801b073417995d3118134a20249bc /src | |
parent | f0799e255a582a61ca9de1eb715af8b9849cc81a (diff) | |
download | trackermap-server-ac2ca17894da7fd43432c63056f6abef4a7a611b.tar.gz trackermap-server-ac2ca17894da7fd43432c63056f6abef4a7a611b.tar.bz2 trackermap-server-ac2ca17894da7fd43432c63056f6abef4a7a611b.zip |
fix: add shutdown hook to close the AMQP connection
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/forward/AmqpClient.java | 7 |
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); } |