Skip to content

Commit 146c9b2

Browse files
authored
Implemented skipping of queue management (#89)
Issue: #69
1 parent 6e83156 commit 146c9b2

File tree

4 files changed

+124
-1
lines changed

4 files changed

+124
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## Version 0.2.0 - tbd
8+
## Version 1.0.0 - tbd
99

1010
### Added
1111

12+
- Configuration option `cds.messaging.services.<key>.connection.properties.skipManagement` to skip creation of queue and subscription.
13+
1214
### Changed
1315

1416
### Fixed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ Your app must be bound to an instance of service `SAP Integration Suite, advance
9797
Please see [Validation of VMR Provisioning](https://help.sap.com/docs/sap-integration-suite/advanced-event-mesh/validation-of-vmr-provisioning) for more information.
9898

9999

100+
### Additional Configuration Options
101+
102+
Additional configuration options for the messaging service are:
103+
104+
Property | Type | Description |
105+
| --- | --- | --- |
106+
| `cds.messaging.services.<key>.connection.properties.skipManagement` | `boolean` | If set to `true`, the plugin will not create a queue or subscription. This is useful if you want to manage these resources manually, default: `false` |
107+
100108

101109
## Support, Feedback, Contributing
102110

cds-feature-advanced-event-mesh/src/main/java/com/sap/cds/feature/messaging/aem/service/AemMessagingService.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.sap.cds.feature.messaging.aem.client.AemManagementClient.ATTR_DEAD_MSG_QUEUE;
44

5+
import com.google.common.annotations.VisibleForTesting;
56
import com.sap.cds.feature.messaging.aem.client.AemManagementClient;
67
import com.sap.cds.feature.messaging.aem.client.AemValidationClient;
78
import com.sap.cds.feature.messaging.aem.jms.AemMessagingConnectionProvider;
@@ -36,6 +37,7 @@ public class AemMessagingService extends AbstractMessagingService {
3637

3738
private volatile BrokerConnection connection;
3839
private volatile Boolean aemBrokerValidated = false;
40+
private volatile Boolean skipManagement = false;
3941

4042
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
4143
protected AemMessagingService(
@@ -50,6 +52,16 @@ protected AemMessagingService(
5052
this.connectionProvider = connectionProvider;
5153
this.managementClient = new AemManagementClient(binding);
5254
this.validationBinding = validationBinding;
55+
56+
Map<String, String> properties = serviceConfig.getConnection().getProperties();
57+
String skipManagementProperty = properties.get("skipManagement");
58+
String skip_ManagementProperty = properties.get("skip-management");
59+
this.skipManagement = Boolean.parseBoolean(skipManagementProperty) || Boolean.parseBoolean(skip_ManagementProperty);
60+
}
61+
62+
@VisibleForTesting
63+
boolean getSkipManagement() {
64+
return this.skipManagement;
5365
}
5466

5567
@Override
@@ -83,11 +95,21 @@ public void stop() {
8395

8496
@Override
8597
protected void removeQueue(String name) throws IOException {
98+
if (this.skipManagement) {
99+
logger.debug("Skipping deletion of queue '{}', skipManagement = {}", name, this.skipManagement);
100+
return;
101+
}
102+
86103
managementClient.removeQueue(name);
87104
}
88105

89106
@Override
90107
protected void createQueue(String name, Map<String, Object> properties) throws IOException {
108+
if (this.skipManagement) {
109+
logger.debug("Skipping creation of queue '{}', skipManagement = {}", name, this.skipManagement);
110+
return;
111+
}
112+
91113
if (properties.containsKey(ATTR_DEAD_MSG_QUEUE)) {
92114
String dmQueue = (String) properties.get(ATTR_DEAD_MSG_QUEUE);
93115
if (managementClient.getQueue(dmQueue) == null) {
@@ -99,6 +121,12 @@ protected void createQueue(String name, Map<String, Object> properties) throws I
99121

100122
@Override
101123
protected void createQueueSubscription(String queue, String topic) throws IOException {
124+
if (this.skipManagement) {
125+
logger.debug("Skipping creation of queue subscription for queue '{}' and topic '{}', skipManagement = {}",
126+
queue, topic, this.skipManagement);
127+
return;
128+
}
129+
102130
managementClient.createQueueSubscription(queue, topic);
103131
}
104132

cds-feature-advanced-event-mesh/src/test/java/com/sap/cds/feature/messaging/aem/service/AemMessagingServiceConfigurationTest.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import static com.sap.cds.services.outbox.OutboxService.unboxed;
44
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertFalse;
56
import static org.junit.jupiter.api.Assertions.assertTrue;
67

78
import com.sap.cds.services.Service;
89
import com.sap.cds.services.environment.CdsProperties;
910
import com.sap.cds.services.environment.CdsProperties.Messaging.MessagingServiceConfig;
1011
import com.sap.cds.services.impl.environment.SimplePropertiesProvider;
12+
import com.sap.cds.services.outbox.OutboxService;
1113
import com.sap.cds.services.runtime.CdsRuntimeConfigurer;
1214
import java.util.List;
1315
import java.util.stream.Collectors;
@@ -140,4 +142,87 @@ void testServiceConfigurationWithInvalidBinding() {
140142

141143
assertTrue(services.isEmpty(), "Expected no services to be configured with invalid binding");
142144
}
145+
146+
@Test
147+
void testServiceConfigurationWithoutSkipManagementConfigured() {
148+
CdsProperties properties = new CdsProperties();
149+
MessagingServiceConfig config = new MessagingServiceConfig("cfg");
150+
config.setBinding("my-aem-instance");
151+
config.getOutbox().setEnabled(false);
152+
properties.getMessaging().getServices().put(config.getName(), config);
153+
154+
CdsRuntimeConfigurer configurer =
155+
CdsRuntimeConfigurer.create(new SimplePropertiesProvider(properties));
156+
157+
configurer.serviceConfigurations();
158+
configurer.eventHandlerConfigurations();
159+
160+
List<AemMessagingService> services =
161+
configurer
162+
.getCdsRuntime()
163+
.getServiceCatalog()
164+
.getServices()
165+
.map(OutboxService::unboxed)
166+
.filter(srv -> srv.getClass().equals(AemMessagingService.class))
167+
.map(srv -> (AemMessagingService) srv)
168+
.toList();
169+
170+
assertFalse(services.stream().findFirst().get().getSkipManagement());
171+
}
172+
173+
@Test
174+
void testServiceConfigurationWithDisabledSkipManagement() {
175+
CdsProperties properties = new CdsProperties();
176+
MessagingServiceConfig config = new MessagingServiceConfig("cfg");
177+
config.setBinding("my-aem-instance");
178+
config.getOutbox().setEnabled(false);
179+
config.getConnection().getProperties().put("skip-management", "false");
180+
properties.getMessaging().getServices().put(config.getName(), config);
181+
182+
CdsRuntimeConfigurer configurer =
183+
CdsRuntimeConfigurer.create(new SimplePropertiesProvider(properties));
184+
185+
configurer.serviceConfigurations();
186+
configurer.eventHandlerConfigurations();
187+
188+
List<AemMessagingService> services =
189+
configurer
190+
.getCdsRuntime()
191+
.getServiceCatalog()
192+
.getServices()
193+
.map(OutboxService::unboxed)
194+
.filter(srv -> srv.getClass().equals(AemMessagingService.class))
195+
.map(srv -> (AemMessagingService) srv)
196+
.toList();
197+
198+
assertFalse(services.stream().findFirst().get().getSkipManagement());
199+
}
200+
201+
@Test
202+
void testServiceConfigurationWithEnabledSkipManagement() {
203+
CdsProperties properties = new CdsProperties();
204+
MessagingServiceConfig config = new MessagingServiceConfig("cfg");
205+
config.setBinding("my-aem-instance");
206+
config.getOutbox().setEnabled(false);
207+
config.getConnection().getProperties().put("skipManagement", "true");
208+
properties.getMessaging().getServices().put(config.getName(), config);
209+
210+
CdsRuntimeConfigurer configurer =
211+
CdsRuntimeConfigurer.create(new SimplePropertiesProvider(properties));
212+
213+
configurer.serviceConfigurations();
214+
configurer.eventHandlerConfigurations();
215+
216+
List<AemMessagingService> services =
217+
configurer
218+
.getCdsRuntime()
219+
.getServiceCatalog()
220+
.getServices()
221+
.map(OutboxService::unboxed)
222+
.filter(srv -> srv.getClass().equals(AemMessagingService.class))
223+
.map(srv -> (AemMessagingService) srv)
224+
.toList();
225+
226+
assertTrue(services.stream().findFirst().get().getSkipManagement());
227+
}
143228
}

0 commit comments

Comments
 (0)