Search in sources :

Example 1 with DivertBinding

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);
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)

Example 2 with DivertBinding

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);
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) Divert(org.apache.activemq.artemis.core.server.Divert)

Example 3 with DivertBinding

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());
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceRegistryImpl(org.apache.activemq.artemis.core.server.impl.ServiceRegistryImpl) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) Divert(org.apache.activemq.artemis.core.server.Divert) Test(org.junit.Test)

Aggregations

Binding (org.apache.activemq.artemis.core.postoffice.Binding)3 DivertBinding (org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)2 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)2 Divert (org.apache.activemq.artemis.core.server.Divert)2 Transformer (org.apache.activemq.artemis.core.server.transformer.Transformer)2 Message (org.apache.activemq.artemis.api.core.Message)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)1 Filter (org.apache.activemq.artemis.core.filter.Filter)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)1 ServiceRegistryImpl (org.apache.activemq.artemis.core.server.impl.ServiceRegistryImpl)1 Test (org.junit.Test)1