use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.
the class ClusterManager method deployBridge.
public synchronized void deployBridge(final BridgeConfiguration config) throws Exception {
if (config.getName() == null) {
ActiveMQServerLogger.LOGGER.bridgeNotUnique();
return;
}
if (config.getQueueName() == null) {
ActiveMQServerLogger.LOGGER.bridgeNoQueue(config.getName());
return;
}
if (config.getForwardingAddress() == null) {
ActiveMQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName());
}
if (bridges.containsKey(config.getName())) {
ActiveMQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName());
return;
}
Transformer transformer = server.getServiceRegistry().getBridgeTransformer(config.getName(), config.getTransformerConfiguration());
Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName()));
if (binding == null) {
ActiveMQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName());
return;
}
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeDeployBridge(config));
}
Queue queue = (Queue) binding.getBindable();
ServerLocatorInternal serverLocator;
if (config.getDiscoveryGroupName() != null) {
DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
if (discoveryGroupConfiguration == null) {
ActiveMQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName());
return;
}
if (config.isHA()) {
serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
} else {
serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
}
} else {
TransportConfiguration[] tcConfigs = configuration.getTransportConfigurations(config.getStaticConnectors());
if (tcConfigs == null) {
ActiveMQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName());
return;
}
if (config.isHA()) {
serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(tcConfigs);
} else {
serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(tcConfigs);
}
}
serverLocator.setIdentity("Bridge " + config.getName());
serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());
// We are going to manually retry on the bridge in case of failure
serverLocator.setReconnectAttempts(0);
serverLocator.setInitialConnectAttempts(0);
serverLocator.setRetryInterval(config.getRetryInterval());
serverLocator.setMaxRetryInterval(config.getMaxRetryInterval());
serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
serverLocator.setConnectionTTL(config.getConnectionTTL());
serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection());
serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection());
serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize());
serverLocator.setProducerWindowSize(config.getProducerWindowSize());
// This will be set to 30s unless it's changed from embedded / testing
// there is no reason to exception the config for this timeout
// since the Bridge is supposed to be non-blocking and fast
// We may expose this if we find a good use case
serverLocator.setCallTimeout(config.getCallTimeout());
serverLocator.addIncomingInterceptor(new IncomingInterceptorLookingForExceptionMessage(this, executor));
if (!config.isUseDuplicateDetection()) {
logger.debug("Bridge " + config.getName() + " is configured to not use duplicate detecion, it will send messages synchronously");
}
clusterLocators.add(serverLocator);
Bridge bridge = new BridgeImpl(serverLocator, config.getInitialConnectAttempts(), config.getReconnectAttempts(), config.getReconnectAttemptsOnSameNode(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), nodeManager.getUUID(), new SimpleString(config.getName()), queue, executorFactory.getExecutor(), FilterImpl.createFilter(config.getFilterString()), SimpleString.toSimpleString(config.getForwardingAddress()), scheduledExecutor, transformer, config.isUseDuplicateDetection(), config.getUser(), config.getPassword(), server);
bridges.put(config.getName(), bridge);
managementService.registerBridge(bridge, config);
bridge.start();
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterDeployBridge(bridge));
}
}
use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.
the class ActiveMQServerImpl method deployDivert.
@Override
public void deployDivert(DivertConfiguration config) throws Exception {
if (config.getName() == null) {
throw ActiveMQMessageBundle.BUNDLE.divertWithNoName();
}
if (config.getAddress() == null) {
ActiveMQServerLogger.LOGGER.divertWithNoAddress();
return;
}
if (config.getForwardingAddress() == null) {
ActiveMQServerLogger.LOGGER.divertWithNoForwardingAddress();
return;
}
SimpleString sName = new SimpleString(config.getName());
if (postOffice.getBinding(sName) != null) {
ActiveMQServerLogger.LOGGER.divertBindingAlreadyExists(sName);
return;
}
SimpleString sAddress = new SimpleString(config.getAddress());
Transformer transformer = getServiceRegistry().getDivertTransformer(config.getName(), config.getTransformerConfiguration());
Filter filter = FilterImpl.createFilter(config.getFilterString());
Divert divert = new DivertImpl(new SimpleString(config.getForwardingAddress()), sName, new SimpleString(config.getRoutingName()), config.isExclusive(), filter, transformer, postOffice, storageManager, config.getRoutingType());
Binding binding = new DivertBinding(storageManager.generateID(), sAddress, divert);
postOffice.addBinding(binding);
managementService.registerDivert(divert, config);
}
use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.
the class ServiceRegistryImpl method getDivertTransformer.
@Override
public Transformer getDivertTransformer(String name, TransformerConfiguration transformerConfiguration) {
Transformer transformer = divertTransformers.get(name);
if (transformer == null && transformerConfiguration != null && transformerConfiguration.getClassName() != null) {
transformer = instantiateTransformer(transformerConfiguration);
addDivertTransformer(name, transformer);
}
return transformer;
}
use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.
the class ServiceRegistryImpl method instantiateTransformer.
private Transformer instantiateTransformer(final TransformerConfiguration transformerConfiguration) {
Transformer transformer = null;
if (transformerConfiguration != null && transformerConfiguration.getClassName() != null) {
try {
transformer = loadClass(transformerConfiguration.getClassName());
transformer.init(Collections.unmodifiableMap(transformerConfiguration.getProperties()));
} catch (Exception e) {
throw ActiveMQMessageBundle.BUNDLE.errorCreatingTransformerClass(e, transformerConfiguration.getClassName());
}
}
return transformer;
}
use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.
the class DivertTest method testInjectedTransformer.
@Test
public void testInjectedTransformer() throws Exception {
final SimpleString ADDRESS = new SimpleString("myAddress");
final String DIVERT = "myDivert";
ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl();
Transformer transformer = new Transformer() {
@Override
public Message transform(Message message) {
return null;
}
};
serviceRegistry.addDivertTransformer(DIVERT, transformer);
ActiveMQServer server = addServer(new ActiveMQServerImpl(null, null, null, null, serviceRegistry));
server.start();
server.waitForActivation(100, TimeUnit.MILLISECONDS);
server.createQueue(ADDRESS, RoutingType.MULTICAST, SimpleString.toSimpleString("myQueue"), null, false, false);
server.deployDivert(new DivertConfiguration().setName(DIVERT).setAddress(ADDRESS.toString()).setForwardingAddress(ADDRESS.toString()));
Collection<Binding> bindings = server.getPostOffice().getBindingsForAddress(ADDRESS).getBindings();
Divert divert = null;
for (Binding binding : bindings) {
if (binding instanceof DivertBinding) {
divert = ((DivertBinding) binding).getDivert();
}
}
assertNotNull(divert);
assertEquals(transformer, divert.getTransformer());
}
Aggregations