Search in sources :

Example 11 with DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project activemq-artemis by apache.

the class OpenWireDivertTestBase method extraServerConfig.

@Override
protected void extraServerConfig(Configuration serverConfig) {
    DivertConfiguration divertConf = new DivertConfiguration().setName("divert1").setRoutingName("divert1").setAddress(testAddress).setForwardingAddress(forwardAddress).setExclusive(isExclusive());
    serverConfig.addDivertConfiguration(divertConf);
}
Also used : DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration)

Example 12 with DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project activemq-artemis by apache.

the class QueueControlTest method testRetryDivertedMessage.

/**
 * Test retry - get a diverted message from DLQ and put on original queue.
 */
@Test
public void testRetryDivertedMessage() throws Exception {
    final SimpleString dla = new SimpleString("DLA");
    final SimpleString dlq = new SimpleString("DLQ");
    final SimpleString forwardingQueue = new SimpleString("forwardingQueue");
    final SimpleString forwardingAddress = new SimpleString("forwardingAddress");
    final SimpleString myTopic = new SimpleString("myTopic");
    final String sampleText = "Put me on DLQ";
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(forwardingAddress.toString(), addressSettings);
    // create target queue, DLQ and source topic
    session.createQueue(dla, RoutingType.MULTICAST, dlq, null, durable);
    session.createQueue(forwardingAddress, RoutingType.MULTICAST, forwardingQueue, null, durable);
    session.createAddress(myTopic, RoutingType.MULTICAST, false);
    DivertConfiguration divert = new DivertConfiguration().setName("local-divert").setRoutingName("some-name").setAddress(myTopic.toString()).setForwardingAddress(forwardingAddress.toString()).setExclusive(false);
    server.deployDivert(divert);
    // Send message to topic.
    ClientProducer producer = session.createProducer(myTopic);
    producer.send(createTextMessage(session, sampleText));
    session.start();
    ClientConsumer clientConsumer = session.createConsumer(forwardingQueue);
    ClientMessage clientMessage = clientConsumer.receive(500);
    clientMessage.acknowledge();
    Assert.assertNotNull(clientMessage);
    Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
    // force a rollback to DLQ
    session.rollback();
    clientMessage = clientConsumer.receiveImmediate();
    Assert.assertNull(clientMessage);
    QueueControl queueControl = createManagementControl(dla, dlq, RoutingType.MULTICAST);
    assertMessageMetrics(queueControl, 1, durable);
    final long messageID = getFirstMessageId(queueControl);
    // Retry the message - i.e. it should go from DLQ to original Queue.
    Assert.assertTrue(queueControl.retryMessage(messageID));
    // Assert DLQ is empty...
    assertMessageMetrics(queueControl, 0, durable);
    // .. and that the message is now on the original queue once more.
    clientMessage = clientConsumer.receive(500);
    // fails because of AMQ222196 !!!
    Assert.assertNotNull(clientMessage);
    clientMessage.acknowledge();
    Assert.assertEquals(sampleText, clientMessage.getBodyBuffer().readString());
    clientConsumer.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 13 with DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project activemq-artemis by apache.

the class ClientSoakTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    clearDataRecreateServerDirs();
    Configuration config = createDefaultConfig(isNetty()).setJournalFileSize(10 * 1024 * 1024);
    server = createServer(IS_JOURNAL, config, -1, -1, new HashMap<String, AddressSettings>());
    DivertConfiguration divert1 = new DivertConfiguration().setName("dv1").setRoutingName("nm1").setAddress(ClientSoakTest.ADDRESS.toString()).setForwardingAddress(ClientSoakTest.DIVERTED_AD1.toString()).setExclusive(true);
    DivertConfiguration divert2 = new DivertConfiguration().setName("dv2").setRoutingName("nm2").setAddress(ClientSoakTest.ADDRESS.toString()).setForwardingAddress(ClientSoakTest.DIVERTED_AD2.toString()).setExclusive(true);
    ArrayList<DivertConfiguration> divertList = new ArrayList<>();
    divertList.add(divert1);
    divertList.add(divert2);
    config.setDivertConfigurations(divertList);
    server.start();
    ServerLocator locator = createFactory(isNetty());
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession();
    session.createQueue(ClientSoakTest.ADDRESS, ClientSoakTest.ADDRESS, true);
    session.createQueue(ClientSoakTest.DIVERTED_AD1, ClientSoakTest.DIVERTED_AD1, true);
    session.createQueue(ClientSoakTest.DIVERTED_AD2, ClientSoakTest.DIVERTED_AD2, true);
    session.close();
    sf.close();
    locator.close();
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) HashMap(java.util.HashMap) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ArrayList(java.util.ArrayList) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Before(org.junit.Before)

Example 14 with DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project wildfly by wildfly.

the class DivertAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = registry.getService(serviceName);
    if (service != null) {
        // The original subsystem initialization is complete; use the control object to create the divert
        if (service.getState() != ServiceController.State.UP) {
            throw MessagingLogger.ROOT_LOGGER.invalidServiceState(serviceName, ServiceController.State.UP, service.getState());
        }
        final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
        DivertConfiguration divertConfiguration = createDivertConfiguration(context, name, model);
        ActiveMQServerControl serverControl = ActiveMQServer.class.cast(service.getValue()).getActiveMQServerControl();
        createDivert(name, divertConfiguration, serverControl);
    }
// else the initial subsystem install is not complete; MessagingSubsystemAdd will add a
// handler that calls addDivertConfigs
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) ServiceName(org.jboss.msc.service.ServiceName) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 15 with DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project wildfly by wildfly.

the class DivertAdd method createDivertConfiguration.

static DivertConfiguration createDivertConfiguration(final OperationContext context, String name, ModelNode model) throws OperationFailedException {
    final String routingName = DivertDefinition.ROUTING_NAME.resolveModelAttribute(context, model).asStringOrNull();
    final String address = DivertDefinition.ADDRESS.resolveModelAttribute(context, model).asString();
    final String forwardingAddress = DivertDefinition.FORWARDING_ADDRESS.resolveModelAttribute(context, model).asString();
    final boolean exclusive = DivertDefinition.EXCLUSIVE.resolveModelAttribute(context, model).asBoolean();
    final String filter = CommonAttributes.FILTER.resolveModelAttribute(context, model).asStringOrNull();
    DivertConfiguration config = new DivertConfiguration().setName(name).setRoutingName(routingName).setAddress(address).setForwardingAddress(forwardingAddress).setExclusive(exclusive).setFilterString(filter);
    final ModelNode transformerClassName = CommonAttributes.TRANSFORMER_CLASS_NAME.resolveModelAttribute(context, model);
    if (transformerClassName.isDefined()) {
        config.setTransformerConfiguration(new TransformerConfiguration(transformerClassName.asString()));
    }
    return config;
}
Also used : TransformerConfiguration(org.apache.activemq.artemis.core.config.TransformerConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)33 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 Configuration (org.apache.activemq.artemis.core.config.Configuration)19 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)18 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)18 Test (org.junit.Test)18 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)17 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)17 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)17 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)17 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)16 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)4 TransformerConfiguration (org.apache.activemq.artemis.core.config.TransformerConfiguration)4 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 Before (org.junit.Before)2 PrintStream (java.io.PrintStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1