use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class BridgeStartTest method testTargetServerUpAndDown.
@Test
public void testTargetServerUpAndDown() throws Exception {
// This test needs to use real files, since it requires duplicate detection, since when the target server is
// shutdown, messages will get resent when it is started, so the dup id cache needs
// to be persisted
Map<String, Object> server0Params = new HashMap<>();
ActiveMQServer server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);
Map<String, Object> server1Params = new HashMap<>();
if (isNetty()) {
server1Params.put("port", org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.DEFAULT_PORT + 1);
} else {
server1Params.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
}
ActiveMQServer server1 = createClusteredServerWithParams(isNetty(), 1, true, 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());
final String bridgeName = "bridge1";
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName(bridgeName).setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(500).setReconnectAttempts(-1).setReconnectAttemptsOnSameNode(0).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);
ServerLocator locator = null;
try {
// Don't start server 1 yet
server0.start();
waitForServerToStart(server0);
locator = ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc);
ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
ClientSession session0 = sf0.createSession(false, true, true);
ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
final int numMessages = 10;
final SimpleString propKey = new SimpleString("testkey");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(false);
message.putIntProperty(propKey, i);
producer0.send(message);
}
// Wait a bit
Thread.sleep(1000);
server1.start();
waitForServerToStart(server1);
ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
ClientSession session1 = sf1.createSession(false, true, true);
ClientConsumer consumer1 = session1.createConsumer(queueName1);
session1.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer1.receive(1000);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
message.acknowledge();
}
Assert.assertNull(consumer1.receiveImmediate());
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(false);
message.putIntProperty(propKey, i);
producer0.send(message);
}
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer1.receive(1000);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
message.acknowledge();
}
Assert.assertNull(consumer1.receiveImmediate());
session1.close();
sf1.close();
BridgeStartTest.log.info("stopping server 1");
server1.stop();
BridgeStartTest.log.info("stopped server 1");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(false);
message.putIntProperty(propKey, i);
producer0.send(message);
}
BridgeStartTest.log.info("sent some more messages");
server1.start();
waitForServerToStart(server1);
BridgeStartTest.log.info("started server1");
sf1 = locator.createSessionFactory(server1tc);
session1 = sf1.createSession(false, true, true);
consumer1 = session1.createConsumer(queueName1);
session1.start();
BridgeStartTest.log.info("started session");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer1.receive(1000);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
message.acknowledge();
}
Assert.assertNull(consumer1.receiveImmediate());
session1.close();
sf1.close();
session0.close();
sf0.close();
locator.close();
} finally {
if (locator != null) {
locator.close();
}
server0.stop();
server1.stop();
}
}
use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class StompWebSocketTest method createServer.
/**
* @return
* @throws Exception
*/
private JMSServerManager createServer() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.PROTOCOLS_PROP_NAME, StompProtocolManagerFactory.STOMP_PROTOCOL_NAME);
params.put(TransportConstants.PORT_PROP_NAME, TransportConstants.DEFAULT_STOMP_PORT + 1);
TransportConfiguration stompTransport = new TransportConfiguration(NettyAcceptorFactory.class.getName(), params);
Configuration config = createBasicConfig().addAcceptorConfiguration(stompTransport).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName())).addQueueConfiguration(new CoreQueueConfiguration().setAddress(getQueueName()).setName(getQueueName()).setDurable(false));
ActiveMQServer activeMQServer = addServer(ActiveMQServers.newActiveMQServer(config));
JMSConfiguration jmsConfig = new JMSConfigurationImpl();
server = new JMSServerManagerImpl(activeMQServer, jmsConfig);
server.setRegistry(null);
return server;
}
use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class PredefinedQueueTest method testDeployPreexistingQueues.
@Test
public void testDeployPreexistingQueues() throws Exception {
final String testAddress = "testAddress";
final String queueName1 = "queue1";
final String queueName2 = "queue2";
final String queueName3 = "queue3";
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(configuration));
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, true, true));
session.createQueue(testAddress, queueName1, null, true);
session.createQueue(testAddress, queueName2, null, true);
session.createQueue(testAddress, queueName3, null, true);
session.close();
sf.close();
server.stop();
CoreQueueConfiguration queue1 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName1);
CoreQueueConfiguration queue2 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName2);
CoreQueueConfiguration queue3 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName3);
configuration.addQueueConfiguration(queue1).addQueueConfiguration(queue2).addQueueConfiguration(queue3);
server.start();
sf = createSessionFactory(locator);
session = addClientSession(sf.createSession(false, true, true));
session.start();
ClientProducer producer = session.createProducer(new SimpleString(testAddress));
ClientConsumer consumer1 = session.createConsumer(queueName1);
ClientConsumer consumer2 = session.createConsumer(queueName2);
ClientConsumer consumer3 = session.createConsumer(queueName3);
final int numMessages = 10;
final SimpleString propKey = new SimpleString("testkey");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(false);
message.putIntProperty(propKey, i);
producer.send(message);
}
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer1.receive(200);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
message.acknowledge();
message = consumer2.receive(200);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
message.acknowledge();
message = consumer3.receive(200);
Assert.assertNotNull(message);
Assert.assertEquals(i, message.getObjectProperty(propKey));
message.acknowledge();
}
Assert.assertNull(consumer1.receiveImmediate());
Assert.assertNull(consumer2.receiveImmediate());
Assert.assertNull(consumer3.receiveImmediate());
}
use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class PredefinedQueueTest method testFailOnCreatePredefinedQueues.
@Test
public void testFailOnCreatePredefinedQueues() throws Exception {
final String testAddress = "testAddress";
final String queueName1 = "queue1";
final String queueName2 = "queue2";
final String queueName3 = "queue3";
CoreQueueConfiguration queue1 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName1);
CoreQueueConfiguration queue2 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName2);
CoreQueueConfiguration queue3 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName3);
List<CoreQueueConfiguration> queueConfs = new ArrayList<>();
queueConfs.add(queue1);
queueConfs.add(queue2);
queueConfs.add(queue3);
configuration.setQueueConfigurations(queueConfs);
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(configuration, false));
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, true, true));
try {
session.createQueue(testAddress, queueName1, "", false);
Assert.fail("Should throw exception");
} catch (ActiveMQQueueExistsException se) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
try {
session.createQueue(testAddress, queueName2, null, false);
Assert.fail("Should throw exception");
} catch (ActiveMQQueueExistsException se) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
try {
session.createQueue(testAddress, queueName3, null, false);
Assert.fail("Should throw exception");
} catch (ActiveMQQueueExistsException se) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
}
use of org.apache.activemq.artemis.core.config.CoreQueueConfiguration in project activemq-artemis by apache.
the class RaceOnSyncLargeMessageOverReplicationTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
System.out.println("Tmp::" + getTemporaryDir());
flagArrived.setCount(1);
flagWait.setCount(1);
TransportConfiguration liveConnector = TransportConfigurationUtils.getNettyConnector(true, 0);
TransportConfiguration liveAcceptor = TransportConfigurationUtils.getNettyAcceptor(true, 0);
TransportConfiguration backupConnector = TransportConfigurationUtils.getNettyConnector(false, 0);
TransportConfiguration backupAcceptor = TransportConfigurationUtils.getNettyAcceptor(false, 0);
backupConfig = createDefaultInVMConfig().setBindingsDirectory(getBindingsDir(0, true)).setJournalDirectory(getJournalDir(0, true)).setPagingDirectory(getPageDir(0, true)).setLargeMessagesDirectory(getLargeMessagesDir(0, true));
liveConfig = createDefaultInVMConfig();
ReplicatedBackupUtils.configureReplicationPair(backupConfig, backupConnector, backupAcceptor, liveConfig, liveConnector, liveAcceptor);
liveServer = createServer(liveConfig);
liveServer.getConfiguration().addQueueConfiguration(new CoreQueueConfiguration().setName("Queue").setAddress("Queue"));
liveServer.start();
waitForServerToStart(liveServer);
// Just to make sure the expression worked
Assert.assertEquals(10000, factory.getMinLargeMessageSize());
Assert.assertEquals(10000, factory.getProducerWindowSize());
Assert.assertEquals(100, factory.getRetryInterval());
Assert.assertEquals(-1, factory.getReconnectAttempts());
Assert.assertTrue(factory.isHA());
connection = (ActiveMQConnection) factory.createConnection();
session = connection.createSession(true, Session.SESSION_TRANSACTED);
queue = session.createQueue("Queue");
producer = session.createProducer(queue);
}
Aggregations