Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use box name from box.json config as RabbitMQ connection name #294

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

@@ -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
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
@@ -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
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
@@ -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() {
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.
@@ -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);
OptimumCode marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.info("Created RabbitMQ connection {} [{}]", connection, connection.hashCode());
addShutdownListenerToConnection(this.connection);
addBlockedListenersToConnection(this.connection);
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.
@@ -160,6 +160,7 @@ class AbstractRabbitRouterIntegrationTest {
prefetchCount: Int = DEFAULT_PREFETCH_COUNT,
confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT
) = ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = rabbitMQContainer.host,
vHost = "",
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.
@@ -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 = "",
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.
@@ -117,6 +117,7 @@ class IntegrationTestRabbitMessageGroupBatchRouter {
prefetchCount: Int = DEFAULT_PREFETCH_COUNT,
confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT
) = ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = rabbitMQContainer.host,
vHost = "",
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.
@@ -123,6 +123,7 @@ class TransportGroupBatchRouterIntegrationTest {
prefetchCount: Int = DEFAULT_PREFETCH_COUNT,
confirmationTimeout: Duration = DEFAULT_CONFIRMATION_TIMEOUT
) = ConnectionManager(
"test-connection",
RabbitMQConfiguration(
host = rabbitMQContainer.host,
vHost = "",