Move Amqp Docker Compose support into spring-boot-amqp
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docker.compose.service.connection.rabbit;
|
||||
|
||||
import org.springframework.boot.amqp.autoconfigure.RabbitConnectionDetails;
|
||||
import org.springframework.boot.amqp.autoconfigure.RabbitConnectionDetails.Address;
|
||||
import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest;
|
||||
import org.springframework.boot.testsupport.container.TestImage;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link RabbitDockerComposeConnectionDetailsFactory}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class RabbitDockerComposeConnectionDetailsFactoryIntegrationTests {
|
||||
|
||||
@DockerComposeTest(composeFile = "rabbit-compose.yaml", image = TestImage.RABBITMQ)
|
||||
void runCreatesConnectionDetails(RabbitConnectionDetails connectionDetails) {
|
||||
assertConnectionDetails(connectionDetails);
|
||||
}
|
||||
|
||||
@DockerComposeTest(composeFile = "rabbit-bitnami-compose.yaml", image = TestImage.BITNAMI_RABBITMQ)
|
||||
void runWithBitnamiImageCreatesConnectionDetails(RabbitConnectionDetails connectionDetails) {
|
||||
assertConnectionDetails(connectionDetails);
|
||||
}
|
||||
|
||||
private void assertConnectionDetails(RabbitConnectionDetails connectionDetails) {
|
||||
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
|
||||
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
|
||||
assertThat(connectionDetails.getVirtualHost()).isEqualTo("/");
|
||||
assertThat(connectionDetails.getAddresses()).hasSize(1);
|
||||
Address address = connectionDetails.getFirstAddress();
|
||||
assertThat(address.host()).isNotNull();
|
||||
assertThat(address.port()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
services:
|
||||
rabbitmq:
|
||||
image: '{imageName}'
|
||||
environment:
|
||||
- 'RABBITMQ_DEFAULT_USER=myuser'
|
||||
- 'RABBITMQ_DEFAULT_PASS=secret'
|
||||
ports:
|
||||
- '5672'
|
||||
@@ -1,8 +0,0 @@
|
||||
services:
|
||||
rabbitmq:
|
||||
image: '{imageName}'
|
||||
environment:
|
||||
- 'RABBITMQ_DEFAULT_USER=myuser'
|
||||
- 'RABBITMQ_DEFAULT_PASS=secret'
|
||||
ports:
|
||||
- '5672'
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docker.compose.service.connection.rabbit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.amqp.autoconfigure.RabbitConnectionDetails;
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
|
||||
|
||||
/**
|
||||
* {@link DockerComposeConnectionDetailsFactory} to create {@link RabbitConnectionDetails}
|
||||
* for a {@code rabbitmq} service.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class RabbitDockerComposeConnectionDetailsFactory
|
||||
extends DockerComposeConnectionDetailsFactory<RabbitConnectionDetails> {
|
||||
|
||||
private static final String[] RABBITMQ_CONTAINER_NAMES = { "rabbitmq", "bitnami/rabbitmq" };
|
||||
|
||||
private static final int RABBITMQ_PORT = 5672;
|
||||
|
||||
protected RabbitDockerComposeConnectionDetailsFactory() {
|
||||
super(RABBITMQ_CONTAINER_NAMES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RabbitConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
|
||||
return new RabbitDockerComposeConnectionDetails(source.getRunningService());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link RabbitConnectionDetails} backed by a {@code rabbitmq}
|
||||
* {@link RunningService}.
|
||||
*/
|
||||
static class RabbitDockerComposeConnectionDetails extends DockerComposeConnectionDetails
|
||||
implements RabbitConnectionDetails {
|
||||
|
||||
private final RabbitEnvironment environment;
|
||||
|
||||
private final List<Address> addresses;
|
||||
|
||||
protected RabbitDockerComposeConnectionDetails(RunningService service) {
|
||||
super(service);
|
||||
this.environment = new RabbitEnvironment(service.env());
|
||||
this.addresses = List.of(new Address(service.host(), service.ports().get(RABBITMQ_PORT)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return this.environment.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return this.environment.getPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVirtualHost() {
|
||||
return "/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Address> getAddresses() {
|
||||
return this.addresses;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docker.compose.service.connection.rabbit;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* RabbitMQ environment details.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class RabbitEnvironment {
|
||||
|
||||
private final String username;
|
||||
|
||||
private final String password;
|
||||
|
||||
RabbitEnvironment(Map<String, String> env) {
|
||||
this.username = env.getOrDefault("RABBITMQ_DEFAULT_USER", env.getOrDefault("RABBITMQ_USERNAME", "guest"));
|
||||
this.password = env.getOrDefault("RABBITMQ_DEFAULT_PASS", env.getOrDefault("RABBITMQ_PASSWORD", "guest"));
|
||||
}
|
||||
|
||||
String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for Docker Compose RabbitMQ service connections.
|
||||
*/
|
||||
package org.springframework.boot.docker.compose.service.connection.rabbit;
|
||||
@@ -25,7 +25,6 @@ org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryTra
|
||||
org.springframework.boot.docker.compose.service.connection.postgres.PostgresJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.postgres.PostgresR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.pulsar.PulsarDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.rabbit.RabbitDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.redis.RedisDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.sqlserver.SqlServerJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.sqlserver.SqlServerR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docker.compose.service.connection.rabbit;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RabbitEnvironment}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class RabbitEnvironmentTests {
|
||||
|
||||
@Test
|
||||
void getUsernameWhenNoRabbitmqDefaultUser() {
|
||||
RabbitEnvironment environment = new RabbitEnvironment(Collections.emptyMap());
|
||||
assertThat(environment.getUsername()).isEqualTo("guest");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getUsernameWhenHasRabbitmqDefaultUser() {
|
||||
RabbitEnvironment environment = new RabbitEnvironment(Map.of("RABBITMQ_DEFAULT_USER", "me"));
|
||||
assertThat(environment.getUsername()).isEqualTo("me");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getUsernameWhenHasRabbitmqUsername() {
|
||||
RabbitEnvironment environment = new RabbitEnvironment(Map.of("RABBITMQ_USERNAME", "me"));
|
||||
assertThat(environment.getUsername()).isEqualTo("me");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getUsernameWhenNoRabbitmqDefaultPass() {
|
||||
RabbitEnvironment environment = new RabbitEnvironment(Collections.emptyMap());
|
||||
assertThat(environment.getPassword()).isEqualTo("guest");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getUsernameWhenHasRabbitmqDefaultPass() {
|
||||
RabbitEnvironment environment = new RabbitEnvironment(Map.of("RABBITMQ_DEFAULT_PASS", "secret"));
|
||||
assertThat(environment.getPassword()).isEqualTo("secret");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getUsernameWhenHasRabbitmqPassword() {
|
||||
RabbitEnvironment environment = new RabbitEnvironment(Map.of("RABBITMQ_PASSWORD", "secret"));
|
||||
assertThat(environment.getPassword()).isEqualTo("secret");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user