use of org.apache.activemq.artemis.core.postoffice.impl.DivertBinding in project activemq-artemis by apache.
the class ActiveMQServerImpl method destroyDivert.
@Override
public void destroyDivert(SimpleString name) throws Exception {
Binding binding = postOffice.getBinding(name);
if (binding == null) {
throw ActiveMQMessageBundle.BUNDLE.noBindingForDivert(name);
}
if (!(binding instanceof DivertBinding)) {
throw ActiveMQMessageBundle.BUNDLE.bindingNotDivert(name);
}
postOffice.removeBinding(name, null, true);
}
use of org.apache.activemq.artemis.core.postoffice.impl.DivertBinding 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.postoffice.impl.DivertBinding 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