From 424e216d3078786439c775c29b170d8390da0278 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Fri, 12 Apr 2024 15:31:11 +0400 Subject: [PATCH] Use box name from `box.json` config as RabbitMQ connection name --- README.md | 6 +++++- .../schema/box/configuration/BoxConfiguration.java | 11 ++++++----- .../common/schema/factory/AbstractCommonFactory.java | 4 ++-- .../impl/rabbitmq/connection/ConnectionManager.java | 6 +++--- .../rabbitmq/AbstractRabbitRouterIntegrationTest.kt | 3 ++- .../impl/rabbitmq/connection/TestConnectionManager.kt | 5 ++++- .../group/IntegrationTestRabbitMessageBatchRouter.kt | 3 ++- .../TransportGroupBatchRouterIntegrationTest.kt | 3 ++- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f1300457d..c12482e6b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# th2 common library (Java) (5.10.0) +# th2 common library (Java) (5.10.1) ## Usage @@ -507,6 +507,10 @@ dependencies { ## Release notes +### 5.10.1-dev + ++ Use box name from `box.json` config as RabbitMQ connection name + ### 5.10.0-dev + Update bom: 4.5.0 -> 4.6.0 diff --git a/src/main/java/com/exactpro/th2/common/schema/box/configuration/BoxConfiguration.java b/src/main/java/com/exactpro/th2/common/schema/box/configuration/BoxConfiguration.java index d35a2db58..6a44d5146 100644 --- a/src/main/java/com/exactpro/th2/common/schema/box/configuration/BoxConfiguration.java +++ b/src/main/java/com/exactpro/th2/common/schema/box/configuration/BoxConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2021 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,28 +17,29 @@ import com.exactpro.th2.common.schema.configuration.Configuration; import com.fasterxml.jackson.annotation.JsonProperty; - import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import static com.exactpro.th2.common.event.EventUtils.requireNonBlankBookName; +import static org.apache.commons.lang3.StringUtils.defaultIfBlank; public class BoxConfiguration extends Configuration { public static final String DEFAULT_BOOK_NAME = "test_book"; + public static final String DEFAULT_BOX_NAME = "th2_component"; @JsonProperty - private String boxName = null; + private String boxName = DEFAULT_BOX_NAME; @JsonProperty private String bookName = DEFAULT_BOOK_NAME; - @Nullable + @NotNull public String getBoxName() { return boxName; } public void setBoxName(@Nullable String boxName) { - this.boxName = boxName; + this.boxName = defaultIfBlank(boxName, DEFAULT_BOX_NAME); } @NotNull diff --git a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java index d1d82e338..8545a0def 100644 --- a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java +++ b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2020-2024 Exactpro (Exactpro Systems Limited) * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -658,7 +658,7 @@ protected PrometheusConfiguration loadPrometheusConfiguration() { } protected ConnectionManager createRabbitMQConnectionManager() { - return new ConnectionManager(getRabbitMqConfiguration(), getConnectionManagerConfiguration()); + return new ConnectionManager(getBoxConfiguration().getBoxName(), getRabbitMqConfiguration(), getConnectionManagerConfiguration()); } protected ConnectionManager getRabbitMqConnectionManager() { diff --git a/src/main/java/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/ConnectionManager.java b/src/main/java/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/ConnectionManager.java index e209c4b4c..aea3e5304 100644 --- a/src/main/java/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/ConnectionManager.java +++ b/src/main/java/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/ConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2020-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,7 +110,7 @@ public ConnectionManagerConfiguration getConfiguration() { return configuration; } - public ConnectionManager(@NotNull RabbitMQConfiguration rabbitMQConfiguration, @NotNull ConnectionManagerConfiguration connectionManagerConfiguration) { + public ConnectionManager(@NotNull String connectionName, @NotNull RabbitMQConfiguration rabbitMQConfiguration, @NotNull ConnectionManagerConfiguration connectionManagerConfiguration) { Objects.requireNonNull(rabbitMQConfiguration, "RabbitMQ configuration cannot be null"); this.configuration = Objects.requireNonNull(connectionManagerConfiguration, "Connection manager configuration can not be null"); @@ -218,7 +218,7 @@ private void turnOffReadiness(Throwable exception) { factory.setSharedExecutor(sharedExecutor); try { - connection = factory.newConnection(); + connection = factory.newConnection(connectionName); LOGGER.info("Created RabbitMQ connection {} [{}]", connection, connection.hashCode()); addShutdownListenerToConnection(this.connection); addBlockedListenersToConnection(this.connection); diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/AbstractRabbitRouterIntegrationTest.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/AbstractRabbitRouterIntegrationTest.kt index 2a0864404..115b1587a 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/AbstractRabbitRouterIntegrationTest.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/AbstractRabbitRouterIntegrationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 Exactpro (Exactpro Systems Limited) + * Copyright 2023-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -160,6 +160,7 @@ class AbstractRabbitRouterIntegrationTest { prefetchCount: Int = DEFAULT_PREFETCH_COUNT, confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT ) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = rabbitMQContainer.host, vHost = "", diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/TestConnectionManager.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/TestConnectionManager.kt index 342b58d9a..7448ef191 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/TestConnectionManager.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/connection/TestConnectionManager.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -418,6 +418,7 @@ class TestConnectionManager { declareQueue(it, queueName) LOGGER.info { "Started with port ${it.amqpPort}" } ConnectionManager( + "test-connection", RabbitMQConfiguration( host = it.host, vHost = "", @@ -894,6 +895,7 @@ class TestConnectionManager { private fun createConnectionManager(container: RabbitMQContainer, configuration: ConnectionManagerConfiguration) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = container.host, vHost = "", @@ -970,6 +972,7 @@ class TestConnectionManager { prefetchCount: Int = DEFAULT_PREFETCH_COUNT, confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT, ) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = rabbitMQContainer.host, vHost = "", diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/group/IntegrationTestRabbitMessageBatchRouter.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/group/IntegrationTestRabbitMessageBatchRouter.kt index b9e953ac5..3f654b9fe 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/group/IntegrationTestRabbitMessageBatchRouter.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/group/IntegrationTestRabbitMessageBatchRouter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,6 +117,7 @@ class IntegrationTestRabbitMessageGroupBatchRouter { prefetchCount: Int = DEFAULT_PREFETCH_COUNT, confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT ) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = rabbitMQContainer.host, vHost = "", diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/TransportGroupBatchRouterIntegrationTest.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/TransportGroupBatchRouterIntegrationTest.kt index 873004c00..119c18c7b 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/TransportGroupBatchRouterIntegrationTest.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/TransportGroupBatchRouterIntegrationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 Exactpro (Exactpro Systems Limited) + * Copyright 2023-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,6 +123,7 @@ class TransportGroupBatchRouterIntegrationTest { prefetchCount: Int = DEFAULT_PREFETCH_COUNT, confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT ) = ConnectionManager( + "test-connection", RabbitMQConfiguration( host = rabbitMQContainer.host, vHost = "",