private AddressSettings createAddressSettings() { AddressSettings addressSettings = new AddressSettings(); addressSettings.setRedistributionDelay(0); addressSettings.setDefaultAddressRoutingType(RoutingType.ANYCAST); return addressSettings; }
@Override protected void configureAddressPolicy(ActiveMQServer server) { Configuration serverConfig = server.getConfiguration(); serverConfig.setJournalType(JournalType.NIO); Map<String, AddressSettings> map = serverConfig.getAddressesSettings(); if (map.size() == 0) { AddressSettings as = new AddressSettings(); as.setDefaultAddressRoutingType(RoutingType.ANYCAST); map.put("#", as); } }
this.server.getAddressSettingsRepository().getMatch("VirtualTopic.#").setDefaultAddressRoutingType(RoutingType.ANYCAST);
@Test public void testSendMessageToNonExistentQueueUsingExplicitDefaultRouting() throws Exception { String nonExistentQueue = RandomUtil.randomString(); server.getAddressSettingsRepository().addMatch(nonExistentQueue, new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST).setDefaultQueueRoutingType(RoutingType.ANYCAST)); sendMessageToNonExistentQueue(getQueuePrefix(), nonExistentQueue, null); }
@Test public void testSendMessageToNonExistentTopicUsingExplicitDefaultRouting() throws Exception { String nonExistentTopic = RandomUtil.randomString(); server.getAddressSettingsRepository().addMatch(nonExistentTopic, new AddressSettings().setDefaultAddressRoutingType(RoutingType.MULTICAST).setDefaultQueueRoutingType(RoutingType.MULTICAST)); sendMessageToNonExistentTopic(getTopicPrefix(), nonExistentTopic, null); }
@Test public void testDurableUnSubscribeWithoutDurableSubName() throws Exception { server.getConfiguration().getWildcardConfiguration().setDelimiter('/'); server.getAddressSettingsRepository().addMatch("/topic/#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.MULTICAST).setDefaultQueueRoutingType(RoutingType.MULTICAST)); conn.connect(defUser, defPass, "myclientid"); String subId = UUID.randomUUID().toString(); String durableSubName = UUID.randomUUID().toString(); String receipt = UUID.randomUUID().toString(); ClientStompFrame frame = conn.createFrame(Stomp.Commands.SUBSCRIBE) .addHeader(Stomp.Headers.Subscribe.DESTINATION, "/topic/test.foo") .addHeader(Stomp.Headers.Unsubscribe.ID, subId) .addHeader(Stomp.Headers.Subscribe.ACK_MODE, Stomp.Headers.Subscribe.AckModeValues.CLIENT_INDIVIDUAL) .addHeader(Stomp.Headers.Subscribe.DURABLE_SUBSCRIPTION_NAME, durableSubName) .addHeader(Stomp.Headers.RECEIPT_REQUESTED, receipt); frame = conn.sendFrame(frame); assertEquals(receipt, frame.getHeader(Stomp.Headers.Response.RECEIPT_ID)); assertTrue(Wait.waitFor(() -> server.locateQueue(SimpleString.toSimpleString("myclientid." + durableSubName)) != null, 2000, 100)); receipt = UUID.randomUUID().toString(); frame = conn.createFrame(Stomp.Commands.UNSUBSCRIBE) .addHeader(Stomp.Headers.Unsubscribe.ID, subId) .addHeader(Stomp.Headers.RECEIPT_REQUESTED, receipt); frame = conn.sendFrame(frame); assertEquals(receipt, frame.getHeader(Stomp.Headers.Response.RECEIPT_ID)); conn.disconnect(); // make sure the durable subscription queue is still there assertTrue(Wait.waitFor(() -> server.locateQueue(SimpleString.toSimpleString("myclientid." + durableSubName)) != null, 2000, 100)); }
@Test(timeout = 60000) public void testSendAMQPReceiveAMQPViaJMSObjectMessage() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST)); String testQueueName = "ConnectionFrameSize"; int nMsgs = 1; ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616"); sendObjectMessages(nMsgs, new JmsConnectionFactory("amqp://localhost:61616")); int count = getMessageCount(server.getPostOffice(), testQueueName); assertEquals(nMsgs, count); receiveJMS(nMsgs, factory); }
@Test(timeout = 60000) public void testSendAMQPReceiveAMQPViaJMSText() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST)); String testQueueName = "ConnectionFrameSize"; int nMsgs = 1; ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616"); sendTextMessages(nMsgs, new JmsConnectionFactory("amqp://localhost:61616")); int count = getMessageCount(server.getPostOffice(), testQueueName); assertEquals(nMsgs, count); receiveJMS(nMsgs, factory); }
@Test public void testAutoCreatedAnycastAddress() throws Exception { conn.connect(defUser, defPass); String queueName = UUID.randomUUID().toString(); SimpleString simpleQueueName = SimpleString.toSimpleString(queueName); Assert.assertNull(server.getAddressInfo(simpleQueueName)); Assert.assertNull(server.locateQueue(simpleQueueName)); server.getAddressSettingsRepository().addMatch(queueName, new AddressSettings() .setDefaultAddressRoutingType(RoutingType.ANYCAST) .setDefaultQueueRoutingType(RoutingType.ANYCAST) ); send(conn, queueName, null, "Hello ANYCAST"); assertTrue("Address and queue should be created now", Wait.waitFor(() -> (server.getAddressInfo(simpleQueueName) != null) && (server.locateQueue(simpleQueueName) != null), 2000, 200)); assertTrue(server.getAddressInfo(simpleQueueName).getRoutingTypes().contains(RoutingType.ANYCAST)); assertEquals(RoutingType.ANYCAST, server.locateQueue(simpleQueueName).getRoutingType()); }
@Test(timeout = 60000) public void testSendAMQPReceiveAMQPViaJMSBytes() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST)); String testQueueName = "ConnectionFrameSize"; int nMsgs = 1; ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616"); sendBytesMessages(nMsgs, new JmsConnectionFactory("amqp://localhost:61616")); int count = getMessageCount(server.getPostOffice(), testQueueName); assertEquals(nMsgs, count); receiveJMS(nMsgs, factory); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test(timeout = 60000) public void testMessageWithAmqpValueListPreservesBodyType() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test(timeout = 60000) public void testMessageWithAmqpSequencePreservesBodyType() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));
@Test(timeout = 60000) public void testSendAMQPReceiveOpenWire() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST)); int nMsgs = 200; AmqpClient client = createAmqpClient(); AmqpConnection connection = addConnection(client.connect()); try { sendMessages(nMsgs, connection); int count = getMessageCount(server.getPostOffice(), testQueueName); assertEquals(nMsgs, count); ConnectionFactory factory = new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616"); receiveJMS(nMsgs, factory); } finally { connection.close(); } }
@Test(timeout = 60000) public void testSendAMQPReceiveCore() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST)); int nMsgs = 200; AmqpClient client = createAmqpClient(); AmqpConnection connection = addConnection(client.connect()); try { sendMessages(nMsgs, connection); int count = getMessageCount(server.getPostOffice(), testQueueName); assertEquals(nMsgs, count); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); receiveJMS(nMsgs, factory); } finally { connection.close(); } }
private void doManyMultiFrameTransfersTestImpl(int maxFrameSize, int payloadSize, int brokerMaxFrameSize) throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));
@Test(timeout = 60000) public void testSendAMQPReceiveAMQP() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));
@Test(timeout = 60000) public void testMessageWithDataAndContentTypeOfTextPreservesBodyType() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));
@Test(timeout = 60000) public void testMessageWithDataAndEmptyBinaryPreservesBody() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST)); AmqpClient client = createAmqpClient(); AmqpConnection connection = addConnection(client.connect()); try { AmqpSession session = connection.createSession(); AmqpSender sender = session.createSender(getTestName()); AmqpMessage message = createAmqpLargeMessageWithNoBody(); message.getWrappedMessage().setBody(new Data(new Binary(new byte[0]))); sender.send(message); sender.close(); AmqpReceiver receiver = session.createReceiver(getTestName()); receiver.flow(1); AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS); assertNotNull("failed to read large AMQP message", received); MessageImpl wrapped = (MessageImpl) received.getWrappedMessage(); assertTrue(wrapped.getBody() instanceof Data); Data body = (Data) wrapped.getBody(); assertTrue(body.getValue() instanceof Binary); Binary payload = (Binary) body.getValue(); assertEquals(0, payload.getLength()); received.accept(); session.close(); } finally { connection.close(); } }
@Test(timeout = 60000) public void testMessageWithAmqpValueAndEmptyBinaryPreservesBody() throws Exception { server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST)); AmqpClient client = createAmqpClient(); AmqpConnection connection = addConnection(client.connect()); try { AmqpSession session = connection.createSession(); AmqpSender sender = session.createSender(getTestName()); AmqpMessage message = createAmqpLargeMessageWithNoBody(); message.getWrappedMessage().setBody(new AmqpValue(new Binary(new byte[0]))); sender.send(message); sender.close(); AmqpReceiver receiver = session.createReceiver(getTestName()); receiver.flow(1); AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS); assertNotNull("failed to read large AMQP message", received); MessageImpl wrapped = (MessageImpl) received.getWrappedMessage(); assertTrue(wrapped.getBody() instanceof AmqpValue); AmqpValue body = (AmqpValue) wrapped.getBody(); assertTrue(body.getValue() instanceof Binary); Binary payload = (Binary) body.getValue(); assertEquals(0, payload.getLength()); received.accept(); session.close(); } finally { connection.close(); } }
messageSize2 > maxFrameSize || messageSize2 > brokerMaxFrameSize); server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));