Skip to content

Commit

Permalink
Use box name from box.json config as RabbitMQ connection name (#294)
Browse files Browse the repository at this point in the history
Co-authored-by: Oleg <oleg.smirnov@exactprosystems.com>
  • Loading branch information
Nikita-Smirnov-Exactpro and OptimumCode committed Apr 16, 2024
1 parent ab92ac7 commit 5d4d954
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# th2 common library (Java) (5.10.0)
# th2 common library (Java) (5.10.1)

## Usage

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
release_version=5.10.0
release_version=5.10.1
description='th2 common library (Java)'
vcs_url=https://github.com/th2-net/th2-common-j
kapt.include.compile.classpath=false
kapt.include.compile.classpath=false
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -160,6 +160,7 @@ class AbstractRabbitRouterIntegrationTest {
prefetchCount: Int = DEFAULT_PREFETCH_COUNT,
confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT
) = ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = rabbitMQContainer.host,
vHost = "",
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -418,6 +418,7 @@ class TestConnectionManager {
declareQueue(it, queueName)
LOGGER.info { "Started with port ${it.amqpPort}" }
ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = it.host,
vHost = "",
Expand Down Expand Up @@ -894,6 +895,7 @@ class TestConnectionManager {

private fun createConnectionManager(container: RabbitMQContainer, configuration: ConnectionManagerConfiguration) =
ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = container.host,
vHost = "",
Expand Down Expand Up @@ -970,6 +972,7 @@ class TestConnectionManager {
prefetchCount: Int = DEFAULT_PREFETCH_COUNT,
confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT,
) = ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = rabbitMQContainer.host,
vHost = "",
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -117,6 +117,7 @@ class IntegrationTestRabbitMessageGroupBatchRouter {
prefetchCount: Int = DEFAULT_PREFETCH_COUNT,
confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT
) = ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = rabbitMQContainer.host,
vHost = "",
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -123,6 +123,7 @@ class TransportGroupBatchRouterIntegrationTest {
prefetchCount: Int = DEFAULT_PREFETCH_COUNT,
confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT
) = ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = rabbitMQContainer.host,
vHost = "",
Expand Down

0 comments on commit 5d4d954

Please sign in to comment.