com.sap.cds.feature.messaging.mq.service.MessageQueuingServiceConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cds-feature-message-queuing Show documentation
Show all versions of cds-feature-message-queuing Show documentation
Message Queuing feature for CDS Services Java
/**************************************************************************
* (C) 2019-2021 SAP SE or an SAP affiliate company. All rights reserved. *
**************************************************************************/
package com.sap.cds.feature.messaging.mq.service;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sap.cds.feature.messaging.mq.jms.MessageQueuingConnectionProvider;
import com.sap.cds.services.environment.CdsProperties.Messaging;
import com.sap.cds.services.environment.CdsProperties.Messaging.MessagingServiceConfig;
import com.sap.cds.services.environment.ServiceBinding;
import com.sap.cds.services.runtime.CdsRuntimeConfiguration;
import com.sap.cds.services.runtime.CdsRuntimeConfigurer;
import com.sap.cds.services.utils.StringUtils;
public class MessageQueuingServiceConfiguration implements CdsRuntimeConfiguration {
private static final Logger logger = LoggerFactory.getLogger(MessageQueuingServiceConfiguration.class);
private static final String BINDING_LABEL = "message-queuing";
@Override
public void services(CdsRuntimeConfigurer configurer) {
Messaging config = configurer.getCdsRuntime().getEnvironment().getCdsProperties().getMessaging();
List bindings = configurer.getCdsRuntime().getEnvironment().getServiceBindings()
.filter(b -> b.matches(null, BINDING_LABEL))
.collect(Collectors.toList());
if(bindings.isEmpty()) {
logger.info("No service bindings with label '{}' found", BINDING_LABEL);
} else {
boolean isSingleBinding = bindings.size() == 1;
bindings.forEach(binding -> {
logger.debug("Starting the initialization of the message-queueing service binding '{}'", binding.getName());
// MQ JMS connection provider
MessageQueuingConnectionProvider connectionProvider = new MessageQueuingConnectionProvider(binding);
// determines whether no configuration is available and the default service should be created
boolean createDefaultService = true;
// check the services configured by binding
List serviceConfigs = config.getServicesByBinding(binding.getName());
if (!serviceConfigs.isEmpty()) {
createDefaultService = false;
serviceConfigs.forEach(serviceConfig -> {
if (serviceConfig.isEnabled()) {
MessageQueuingService service = new MessageQueuingService(serviceConfig, binding, connectionProvider, configurer.getCdsRuntime());
// register the service
configurer.service(service);
}
});
}
// check the services configured by kind if only one service binding is available
List serviceConfigsByKind = config.getServicesByKind(BINDING_LABEL);
if (isSingleBinding && !serviceConfigsByKind.isEmpty()) {
createDefaultService = false;
serviceConfigsByKind.forEach(serviceConfig -> {
// check that the service is enabled and whether not already found by name or binding
if (serviceConfig.isEnabled() && !serviceConfigs.stream().anyMatch(c -> c.getName().equals(serviceConfig.getName()))) {
MessageQueuingService service = new MessageQueuingService(serviceConfig, binding, connectionProvider, configurer.getCdsRuntime());
// register the service
configurer.service(service);
}
});
}
if (createDefaultService) {
// otherwise create default service instance for the binding
MessagingServiceConfig defConfig = config.getService(binding.getName());
if (StringUtils.isEmpty(defConfig.getBinding()) && StringUtils.isEmpty(defConfig.getKind())) {
MessageQueuingService service = new MessageQueuingService(defConfig, binding, connectionProvider, configurer.getCdsRuntime());
// register the service
configurer.service(service);
} else {
logger.warn("Could not create service for binding '{}': A configuration with the same name is already defined for another kind or binding.", binding.getName());
}
}
logger.debug("Finished the initialization of the message-queueing service binding '{}'", binding.getName());
});
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy