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);
}
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();
}
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();
}
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
}
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;
}
Aggregations