|
| 1 | +/* |
| 2 | + * Copyright 2012-2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.docker.compose.service.connection.activemq; |
| 18 | + |
| 19 | +import org.springframework.boot.autoconfigure.amqp.RabbitConnectionDetails; |
| 20 | +import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionDetails; |
| 21 | +import org.springframework.boot.docker.compose.core.RunningService; |
| 22 | +import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory; |
| 23 | +import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource; |
| 24 | + |
| 25 | +/** |
| 26 | + * {@link DockerComposeConnectionDetailsFactory} to create |
| 27 | + * {@link ActiveMQConnectionDetails} for an {@code activemq} service. |
| 28 | + * |
| 29 | + * @author Stephane Nicoll |
| 30 | + */ |
| 31 | +class ActiveMQDockerComposeConnectionDetailsFactory |
| 32 | + extends DockerComposeConnectionDetailsFactory<ActiveMQConnectionDetails> { |
| 33 | + |
| 34 | + private static final int ACTIVEMQ_PORT = 61616; |
| 35 | + |
| 36 | + protected ActiveMQDockerComposeConnectionDetailsFactory() { |
| 37 | + super("symptoma/activemq"); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected ActiveMQConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) { |
| 42 | + return new ActiveMQDockerComposeConnectionDetails(source.getRunningService()); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * {@link RabbitConnectionDetails} backed by a {@code rabbitmq} |
| 47 | + * {@link RunningService}. |
| 48 | + */ |
| 49 | + static class ActiveMQDockerComposeConnectionDetails extends DockerComposeConnectionDetails |
| 50 | + implements ActiveMQConnectionDetails { |
| 51 | + |
| 52 | + private final ActiveMQEnvironment environment; |
| 53 | + |
| 54 | + private final String brokerUrl; |
| 55 | + |
| 56 | + protected ActiveMQDockerComposeConnectionDetails(RunningService service) { |
| 57 | + super(service); |
| 58 | + this.environment = new ActiveMQEnvironment(service.env()); |
| 59 | + this.brokerUrl = "tcp://" + service.host() + ":" + service.ports().get(ACTIVEMQ_PORT); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public String getBrokerUrl() { |
| 64 | + return this.brokerUrl; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public String getUser() { |
| 69 | + return this.environment.getUser(); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public String getPassword() { |
| 74 | + return this.environment.getPassword(); |
| 75 | + } |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | +} |
0 commit comments