Merge pull request #55 from cborealis/feature/activemq-artemis
Adding support for ActiveMQ Artemis
This commit is contained in:
27
README.md
27
README.md
@@ -34,6 +34,33 @@ Each auto-configuration is triggered by the type of binding. Each auto-configur
|
||||
|
||||
`{<key>}` indicates that the value is the contents of the secret with the given key.
|
||||
|
||||
### ActiveMQ Artemis
|
||||
Type: `artemis`
|
||||
Disable Property: `org.springframework.cloud.bindings.boot.artemis.enable`
|
||||
|
||||
| Property | Value
|
||||
| -------- | ------------------
|
||||
| `spring.artemis.host` | `{host}`
|
||||
| `spring.artemis.mode` | `{mode}`
|
||||
| `spring.artemis.password` | `{password}`
|
||||
| `spring.artemis.port` | `{port}`
|
||||
| `spring.artemis.user` | `{user}`
|
||||
| `spring.artemis.embedded.cluster-password` | `{embedded.cluster-password}`
|
||||
| `spring.artemis.embedded.data-directory` | `{embedded.data-directory}`
|
||||
| `spring.artemis.embedded.enabled` | `{embedded.enabled}`
|
||||
| `spring.artemis.embedded.persistent` | `{embedded.persistent}`
|
||||
| `spring.artemis.embedded.queues` | `{embedded.queues}`
|
||||
| `spring.artemis.embedded.server-id` | `{embedded.server-id}`
|
||||
| `spring.artemis.embedded.topics` | `{embedded.topics}`
|
||||
| `spring.artemis.pool.block-if-full` | `{pool.block-if-full}`
|
||||
| `spring.artemis.pool.block-if-full-timeout` | `{pool.block-if-full-timeout}`
|
||||
| `spring.artemis.pool.enabled` | `{pool.enabled}`
|
||||
| `spring.artemis.pool.idle-timeout` | `{pool.idle-timeout}`
|
||||
| `spring.artemis.pool.max-connections` | `{pool.max-connections}`
|
||||
| `spring.artemis.pool.max-sessions-per-connection` | `{pool.max-sessions-per-connection}`
|
||||
| `spring.artemis.pool.time-between-expiration-check` | `{pool.time-between-expiration-check}`
|
||||
| `spring.artemis.pool.use-anonymous-producers` | `{pool.use-anonymous-producers}`
|
||||
|
||||
### Cassandra
|
||||
Type: `cassandra`
|
||||
Disable Property: `org.springframework.cloud.bindings.boot.cassandra.enable`
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2020 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
|
||||
*
|
||||
* http://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.cloud.bindings.boot;
|
||||
|
||||
import org.springframework.cloud.bindings.Binding;
|
||||
import org.springframework.cloud.bindings.Bindings;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled;
|
||||
|
||||
/**
|
||||
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}.
|
||||
*/
|
||||
public final class ArtemisBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
|
||||
|
||||
/**
|
||||
* The {@link Binding} type that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String TYPE = "artemis";
|
||||
|
||||
@Override
|
||||
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
|
||||
if (!isTypeEnabled(environment, TYPE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bindings.filterBindings(TYPE).forEach(binding -> {
|
||||
MapMapper map = new MapMapper(binding.getSecret(), properties);
|
||||
|
||||
map.from("host").to("spring.artemis.host");
|
||||
map.from("mode").to("spring.artemis.mode");
|
||||
map.from("password").to("spring.artemis.password");
|
||||
map.from("port").to("spring.artemis.port");
|
||||
map.from("user").to("spring.artemis.user");
|
||||
|
||||
map.from("embedded.cluster-password").to("spring.artemis.embedded.cluster-password");
|
||||
map.from("embedded.data-directory").to("spring.artemis.embedded.data-directory");
|
||||
map.from("embedded.enabled").to("spring.artemis.embedded.enabled");
|
||||
map.from("embedded.persistent").to("spring.artemis.embedded.persistent");
|
||||
map.from("embedded.queues").to("spring.artemis.embedded.queues");
|
||||
map.from("embedded.server-id").to("spring.artemis.embedded.server-id");
|
||||
map.from("embedded.topics").to("spring.artemis.embedded.topics");
|
||||
|
||||
map.from("pool.block-if-full").to("spring.rabbitmq.pool.block-if-full");
|
||||
map.from("pool.block-if-full-timeout").to("spring.rabbitmq.pool.block-if-full-timeout");
|
||||
map.from("pool.enabled").to("spring.rabbitmq.pool.enabled");
|
||||
map.from("pool.idle-timeout").to("spring.rabbitmq.pool.idle-timeout");
|
||||
map.from("pool.max-connections").to("spring.rabbitmq.pool.max-connections");
|
||||
map.from("pool.max-sessions-per-connection").to("spring.rabbitmq.pool.max-sessions-per-connection");
|
||||
map.from("pool.time-between-expiration-check").to("spring.rabbitmq.pool.time-between-expiration-check");
|
||||
map.from("pool.use-anonymous-producers").to("spring.rabbitmq.pool.use-anonymous-producers");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.springframework.cloud.bindings.boot.BindingSpecificEnvironmentPostProcessor
|
||||
# Included implementations
|
||||
org.springframework.cloud.bindings.boot.BindingsPropertiesProcessor=\
|
||||
org.springframework.cloud.bindings.boot.ArtemisBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.CassandraBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.ConfigServerBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.CouchbaseBindingsPropertiesProcessor, \
|
||||
@@ -26,4 +27,4 @@ org.springframework.cloud.bindings.boot.BindingsPropertiesProcessor=\
|
||||
org.springframework.cloud.bindings.boot.SpringSecurityOAuth2BindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.SqlServerBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.boot.WavefrontBindingsPropertiesProcessor
|
||||
org.springframework.cloud.bindings.boot.WavefrontBindingsPropertiesProcessor
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2020 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
|
||||
*
|
||||
* http://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.cloud.bindings.boot;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.cloud.bindings.Binding;
|
||||
import org.springframework.cloud.bindings.Bindings;
|
||||
import org.springframework.cloud.bindings.FluentMap;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.boot.ArtemisBindingsPropertiesProcessor.TYPE;
|
||||
|
||||
@DisplayName("ActiveMQ Artemis BindingsPropertiesProcessor")
|
||||
final class ArtemisBindingsPropertiesProcessorTest {
|
||||
|
||||
private final Bindings bindings = new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
new FluentMap()
|
||||
.withEntry(Binding.TYPE, TYPE)
|
||||
.withEntry("mode", "EMBEDDED")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("user", "test-user")
|
||||
.withEntry("password", "test-password")
|
||||
)
|
||||
);
|
||||
|
||||
private final MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
private final HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
new ArtemisBindingsPropertiesProcessor().process(environment, bindings, properties);
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.artemis.mode", "EMBEDDED")
|
||||
.containsEntry("spring.artemis.host", "test-host")
|
||||
.containsEntry("spring.artemis.password", "test-password")
|
||||
.containsEntry("spring.artemis.port", "test-port")
|
||||
.containsEntry("spring.artemis.user", "test-user");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("can be disabled")
|
||||
void disabled() {
|
||||
environment.setProperty("org.springframework.cloud.bindings.boot.artemis.enable", "false");
|
||||
|
||||
new ArtemisBindingsPropertiesProcessor().process(environment, bindings, properties);
|
||||
|
||||
assertThat(properties).isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -104,7 +104,7 @@ final class BindingSpecificEnvironmentPostProcessorTest {
|
||||
@Test
|
||||
@DisplayName("included implementations are registered")
|
||||
void includedImplementations() {
|
||||
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(19);
|
||||
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(20);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user