use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class BridgeTest method internalTestMessageLoss.
/**
* This test will ignore messages
* What will cause the bridge to fail with a timeout
* The bridge should still recover the failure and reconnect on that case
*/
public void internalTestMessageLoss(final boolean largeMessage) throws Exception {
class MyInterceptor implements Interceptor {
public boolean ignoreSends = true;
public CountDownLatch latch;
MyInterceptor(int numberOfIgnores) {
latch = new CountDownLatch(numberOfIgnores);
}
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
if (ignoreSends && packet instanceof SessionSendMessage || ignoreSends && packet instanceof SessionSendLargeMessage || ignoreSends && packet instanceof SessionSendContinuationMessage && !((SessionSendContinuationMessage) packet).isContinues()) {
IntegrationTestLogger.LOGGER.info("IGNORED: " + packet);
latch.countDown();
return false;
} else {
IntegrationTestLogger.LOGGER.info(packet);
return true;
}
}
}
MyInterceptor myInterceptor = new MyInterceptor(3);
Map<String, Object> server0Params = new HashMap<>();
server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);
Map<String, Object> server1Params = new HashMap<>();
addTargetParameters(server1Params);
server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
final String testAddress = "testAddress";
final String queueName0 = "queue0";
final String forwardAddress = "forwardAddress";
final String queueName1 = "queue1";
TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
HashMap<String, TransportConfiguration> connectors = new HashMap<>();
connectors.put(server1tc.getName(), server1tc);
server0.getConfiguration().setConnectorConfigurations(connectors);
final int messageSize = 1024;
final int numMessages = 1;
ArrayList<String> connectorConfig = new ArrayList<>();
connectorConfig.add(server1tc.getName());
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(100).setReconnectAttempts(-1).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(numMessages * messageSize / 2).setStaticConnectors(connectorConfig).setCallTimeout(500);
List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
server1.start();
server1.getRemotingService().addIncomingInterceptor(myInterceptor);
server0.start();
locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
ClientSessionFactory sf0 = addSessionFactory(locator.createSessionFactory(server0tc));
ClientSessionFactory sf1 = addSessionFactory(locator.createSessionFactory(server1tc));
ClientSession session0 = sf0.createSession(false, true, true);
ClientSession session1 = sf1.createSession(false, true, true);
ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
ClientConsumer consumer1 = session1.createConsumer(queueName1);
session1.start();
final byte[] bytes = new byte[messageSize];
final SimpleString propKey = new SimpleString("testkey");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(true);
if (largeMessage) {
message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(10 * 1024));
}
message.putIntProperty(propKey, i);
message.getBodyBuffer().writeBytes(bytes);
producer0.send(message);
}
assertTrue("where is the countDown?", myInterceptor.latch.await(30, TimeUnit.SECONDS));
myInterceptor.ignoreSends = false;
server1.getRemotingService().removeIncomingInterceptor(myInterceptor);
IntegrationTestLogger.LOGGER.info("No longer ignoring packets.");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer1.receive(30000);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
if (largeMessage) {
readLargeMessages(message, 10);
}
message.acknowledge();
}
Assert.assertNull(consumer1.receiveImmediate());
session0.close();
session1.close();
sf0.close();
sf1.close();
closeFields();
assertEquals("there should be no queues", 0, loadQueues(server0).size());
}
use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class BridgeTest method testWithTransformerProperties.
@Test
public void testWithTransformerProperties() throws Exception {
final String propKey = "bridged";
final String propValue = "true";
TransformerConfiguration transformerConfiguration = new TransformerConfiguration(AddHeadersTransformer.class.getName());
transformerConfiguration.getProperties().put(propKey, propValue);
Map<String, Object> server0Params = new HashMap<>();
server0 = createClusteredServerWithParams(isNetty(), 0, false, server0Params);
Map<String, Object> server1Params = new HashMap<>();
addTargetParameters(server1Params);
server1 = createClusteredServerWithParams(isNetty(), 1, false, server1Params);
final String testAddress = "testAddress";
final String queueName0 = "queue0";
final String forwardAddress = "forwardAddress";
final String queueName1 = "queue1";
Map<String, TransportConfiguration> connectors = new HashMap<>();
TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
connectors.put(server1tc.getName(), server1tc);
server0.getConfiguration().setConnectorConfigurations(connectors);
ArrayList<String> staticConnectors = new ArrayList<>();
staticConnectors.add(server1tc.getName());
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setTransformerConfiguration(transformerConfiguration).setRetryInterval(1000).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(1024).setStaticConnectors(staticConnectors);
List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
server1.start();
server0.start();
locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
ClientSession session0 = sf0.createSession(false, true, true);
ClientSession session1 = sf1.createSession(false, true, true);
ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
ClientConsumer consumer1 = session1.createConsumer(queueName1);
session1.start();
final int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(true);
message.getBodyBuffer().writeString("doo be doo be doo be doo");
producer0.send(message);
}
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer1.receive(200);
Assert.assertNotNull(message);
String messagePropVal = message.getStringProperty(propKey);
Assert.assertEquals(propValue, messagePropVal);
String sval = message.getBodyBuffer().readString();
Assert.assertEquals("doo be doo be doo be doo", sval);
message.acknowledge();
}
Assert.assertNull(consumer1.receiveImmediate());
session0.close();
session1.close();
sf0.close();
sf1.close();
if (server0.getConfiguration().isPersistenceEnabled()) {
assertEquals(0, loadQueues(server0).size());
}
}
use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class BridgeTest method testBridgeWithPaging.
@Test
public void testBridgeWithPaging() throws Exception {
ActiveMQServer server0 = null;
ActiveMQServer server1 = null;
final int PAGE_MAX = 10 * 1024;
final int PAGE_SIZE = 1 * 1024;
try {
Map<String, Object> server0Params = new HashMap<>();
server0 = createClusteredServerWithParams(isNetty(), 0, true, PAGE_SIZE, PAGE_MAX, server0Params);
Map<String, Object> server1Params = new HashMap<>();
addTargetParameters(server1Params);
server1 = createClusteredServerWithParams(isNetty(), 1, true, PAGE_SIZE, PAGE_MAX, server1Params);
server1.getConfiguration().setJournalBufferTimeout_AIO(10).setJournalBufferTimeout_NIO(10);
final String testAddress = "testAddress";
final String queueName0 = "queue0";
final String forwardAddress = "forwardAddress";
final String queueName1 = "queue1";
Map<String, TransportConfiguration> connectors = new HashMap<>();
TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
connectors.put(server1tc.getName(), server1tc);
server0.getConfiguration().setConnectorConfigurations(connectors);
server0.getConfiguration().setIDCacheSize(20000).setJournalBufferTimeout_NIO(10).setJournalBufferTimeout_AIO(10);
ArrayList<String> staticConnectors = new ArrayList<>();
staticConnectors.add(server1tc.getName());
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(1).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(1).setStaticConnectors(staticConnectors);
bridgeConfiguration.setCallTimeout(1000);
bridgeConfiguration.setUseDuplicateDetection(true);
List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
List<String> interceptorToStop = new ArrayList<>();
interceptorToStop.add(StopInterceptor.class.getName());
server1.getConfiguration().setIncomingInterceptorClassNames(interceptorToStop);
StopInterceptor.serverToStop = server0;
server1.start();
server0.start();
locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
ClientSession session0 = sf0.createSession(false, false, true);
ClientSession session1 = sf1.createSession(false, true, true);
ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
ClientConsumer consumer1 = session1.createConsumer(queueName1);
session1.start();
final int numMessages = 200;
final SimpleString propKey = new SimpleString("testkey");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(true);
message.getBodyBuffer().writeBytes(new byte[512]);
message.putIntProperty(propKey, i);
producer0.send(message);
}
session0.commit();
assertTrue(StopInterceptor.latch.await(1, TimeUnit.HOURS));
StopInterceptor.thread.join(15000);
if (StopInterceptor.thread.isAlive()) {
System.out.println(threadDump("Still alive, stop didn't work!!!"));
fail("Thread that should restart the server still alive");
}
// Restarting the server
server0.start();
HashMap<Integer, AtomicInteger> receivedMsg = new HashMap<>();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer1.receive(5000);
if (message == null) {
break;
}
Integer msgKey = message.getIntProperty(propKey);
AtomicInteger msgCount = receivedMsg.get(msgKey);
if (msgKey.intValue() != i) {
System.err.println("Message " + msgCount + " received out of order, expected to be " + i + " it's acceptable but not the ideal!");
}
if (msgCount == null) {
msgCount = new AtomicInteger();
receivedMsg.put(msgKey, msgCount);
}
msgCount.incrementAndGet();
if (i % 500 == 0)
System.out.println("received " + i);
}
boolean failed = false;
if (consumer1.receiveImmediate() != null) {
System.err.println("Unexpected message received");
failed = true;
}
for (int i = 0; i < numMessages; i++) {
AtomicInteger msgCount = receivedMsg.get(Integer.valueOf(i));
if (msgCount == null) {
System.err.println("Msg " + i + " wasn't received");
failed = true;
} else if (msgCount.get() > 1) {
System.err.println("msg " + i + " was received " + msgCount.get() + " times");
failed = true;
}
}
assertFalse("Test failed", failed);
session0.close();
session1.close();
sf0.close();
sf1.close();
} finally {
if (locator != null) {
locator.close();
}
try {
server0.stop();
} catch (Throwable ignored) {
}
try {
server1.stop();
} catch (Throwable ignored) {
}
}
assertEquals(0, loadQueues(server0).size());
}
use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class BridgeFailoverTest method internalTestFailoverOnBridge.
public void internalTestFailoverOnBridge(int retriesSameNode) throws Exception {
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration();
String ORIGINAL_QUEUE = "noCluster.originalQueue";
String TARGET_QUEUE = "noCluster.targetQueue";
bridgeConfiguration.setHA(true);
List<String> connectors = new ArrayList<>();
connectors.add("target-4");
connectors.add("backup-4");
bridgeConfiguration.setName("Bridge-for-test");
bridgeConfiguration.setStaticConnectors(connectors);
bridgeConfiguration.setQueueName(ORIGINAL_QUEUE);
bridgeConfiguration.setForwardingAddress(TARGET_QUEUE);
bridgeConfiguration.setRetryInterval(100);
bridgeConfiguration.setConfirmationWindowSize(1);
bridgeConfiguration.setReconnectAttempts(-1);
bridgeConfiguration.setReconnectAttemptsOnSameNode(retriesSameNode);
bridgeConfiguration.setHA(true);
servers[2].getConfiguration().getBridgeConfigurations().add(bridgeConfiguration);
for (ActiveMQServer server : servers) {
server.getConfiguration().getQueueConfigurations().add(new CoreQueueConfiguration().setAddress(ORIGINAL_QUEUE).setName(ORIGINAL_QUEUE));
server.getConfiguration().getQueueConfigurations().add(new CoreQueueConfiguration().setAddress(TARGET_QUEUE).setName(TARGET_QUEUE));
}
startServers();
BridgeImpl bridge = (BridgeImpl) servers[2].getClusterManager().getBridges().get("Bridge-for-test");
assertNotNull(bridge);
long timeout = System.currentTimeMillis() + 5000;
while (bridge.getTargetNodeFromTopology() == null && timeout > System.currentTimeMillis()) {
Thread.sleep(100);
}
assertNotNull(bridge.getTargetNodeFromTopology());
// The server where the bridge source is configured at
ServerLocator locatorProducer = createLocator(false, 2);
ClientSessionFactory factory = addSessionFactory(locatorProducer.createSessionFactory());
ClientSession session = addClientSession(factory.createSession(false, false));
ClientProducer producer = addClientProducer(session.createProducer(ORIGINAL_QUEUE));
for (int i = 0; i < 100; i++) {
ClientMessage msg = session.createMessage(true);
msg.putIntProperty("i", i);
producer.send(msg);
}
session.commit();
ServerLocator locatorConsumer = createLocator(false, 4);
ClientSessionFactory factoryConsumer = addSessionFactory(locatorConsumer.createSessionFactory());
ClientSession sessionConsumer = addClientSession(factoryConsumer.createSession(false, false));
ClientConsumer consumer = sessionConsumer.createConsumer(TARGET_QUEUE);
sessionConsumer.start();
for (int i = 0; i < 100; i++) {
ClientMessage message = consumer.receive(10000);
assertNotNull(message);
message.acknowledge();
}
// We rollback as we will receive them again
sessionConsumer.rollback();
factoryConsumer.close();
sessionConsumer.close();
crashAndWaitForFailure(servers[4], locatorConsumer);
locatorConsumer.close();
assertTrue("Backup server didn't activate.", backupServers[4].waitForActivation(5, TimeUnit.SECONDS));
for (int i = 100; i < 200; i++) {
ClientMessage msg = session.createMessage(true);
msg.putIntProperty("i", i);
producer.send(msg);
}
session.commit();
locatorConsumer = createLocator(false, 9);
factoryConsumer = addSessionFactory(locatorConsumer.createSessionFactory());
sessionConsumer = addClientSession(factoryConsumer.createSession());
consumer = sessionConsumer.createConsumer(TARGET_QUEUE);
sessionConsumer.start();
for (int i = 0; i < 200; i++) {
ClientMessage message = consumer.receive(10000);
assertNotNull(message);
message.acknowledge();
}
sessionConsumer.commit();
}
use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class BridgeFailoverTest method testSimpleConnectOnMultipleNodes.
@Test
public void testSimpleConnectOnMultipleNodes() throws Exception {
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration();
String ORIGINAL_QUEUE = "noCluster.originalQueue";
String TARGET_QUEUE = "noCluster.targetQueue";
bridgeConfiguration.setHA(true);
List<String> connectors = new ArrayList<>();
connectors.add("target-4");
connectors.add("backup-4");
bridgeConfiguration.setName("Bridge-for-test");
bridgeConfiguration.setStaticConnectors(connectors);
bridgeConfiguration.setQueueName(ORIGINAL_QUEUE);
bridgeConfiguration.setForwardingAddress(TARGET_QUEUE);
bridgeConfiguration.setRetryInterval(100);
bridgeConfiguration.setConfirmationWindowSize(1);
bridgeConfiguration.setReconnectAttempts(-1);
servers[2].getConfiguration().getBridgeConfigurations().add(bridgeConfiguration);
for (ActiveMQServer server : servers) {
server.getConfiguration().getQueueConfigurations().add(new CoreQueueConfiguration().setAddress(ORIGINAL_QUEUE).setName(ORIGINAL_QUEUE));
server.getConfiguration().getQueueConfigurations().add(new CoreQueueConfiguration().setAddress(TARGET_QUEUE).setName(TARGET_QUEUE));
}
startServers();
// The server where the bridge source is configured at
ServerLocator locator = createLocator(false, 2);
ClientSessionFactory factory = addSessionFactory(locator.createSessionFactory());
ClientSession session = addClientSession(factory.createSession(false, false));
ClientProducer producer = addClientProducer(session.createProducer(ORIGINAL_QUEUE));
for (int i = 0; i < 100; i++) {
ClientMessage msg = session.createMessage(true);
msg.putIntProperty("i", i);
producer.send(msg);
}
session.commit();
ServerLocator locatorConsumer = createLocator(false, 4);
ClientSessionFactory factoryConsumer = addSessionFactory(locatorConsumer.createSessionFactory());
ClientSession sessionConsumer = addClientSession(factoryConsumer.createSession(false, false));
ClientConsumer consumer = sessionConsumer.createConsumer(TARGET_QUEUE);
sessionConsumer.start();
for (int i = 0; i < 100; i++) {
ClientMessage message = consumer.receive(10000);
assertNotNull(message);
message.acknowledge();
}
sessionConsumer.commit();
}
Aggregations