Skip to content

Commit

Permalink
Use box name from box.json config as RabbitMQ connection name
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Apr 12, 2024
1 parent ab92ac7 commit 424e216
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 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
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 424e216

Please sign in to comment.