if (jbd.isQueue() && response.isAutoCreateQueues()) { session.createAddress(jbd.getSimpleAddress(), RoutingType.ANYCAST, true); createQueue(jbd, RoutingType.ANYCAST, jbd.getSimpleAddress(), null, true, true, response.getDefaultMaxConsumers(), response.isDefaultPurgeOnNoConsumers(), response.isDefaultExclusive(), response.isDefaultLastValueQueue()); } else if (!jbd.isQueue() && response.isAutoCreateAddresses()) { session.createAddress(jbd.getSimpleAddress(), RoutingType.MULTICAST, true); } else { throw new InvalidDestinationException("Destination " + jbd.getName() + " does not exist");
clientSession.createAddress(address, RoutingType.ANYCAST, true); if (destination.isTemporary()) { clientSession.createAddress(address, RoutingType.MULTICAST, true); } else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) { throw new InvalidDestinationException("Destination " + address + " does not exist");
session.createAddress(dest.getSimpleAddress(), RoutingType.MULTICAST, true); } else { throw new InvalidDestinationException("Topic " + dest.getName() + " does not exist");
@Override protected void createClient() { boolean browseOnly = false; try { if (!session.queueQuery(queueName).isExists() && autoCreateQueue) { log.warn("{}: queue does not exist - creating queue: address = {}, name = {}", this.getClass().getSimpleName(), queueName.toString(), queueName.toString()); session.createAddress(queueName, RoutingType.MULTICAST, true); session.createQueue(queueName, queueName); } consumer = session.createConsumer(queueName, browseOnly); } catch (ActiveMQException amqEx) { throw new ActiveMQClientResourceException(String.format("Error creating consumer for queueName %s", queueName.toString()), amqEx); } }
@Override protected void createClient() { boolean browseOnly = false; try { if (!session.queueQuery(queueName).isExists() && autoCreateQueue) { log.warn("{}: queue does not exist - creating queue: address = {}, name = {}", this.getClass().getSimpleName(), queueName.toString(), queueName.toString()); session.createAddress(queueName, RoutingType.MULTICAST, true); session.createQueue(queueName, queueName); } consumer = session.createConsumer(queueName, browseOnly); } catch (ActiveMQException amqEx) { throw new ActiveMQClientResourceException(String.format("Error creating consumer for queueName %s", queueName.toString()), amqEx); } }
protected Queue createCoreQueue(final String queueName) throws Exception { SimpleString address = SimpleString.toSimpleString(queueName); clientSession.createAddress(address, RoutingType.ANYCAST, false); return new ActiveMQQueue(queueName); }
protected Queue createAddressOnlyAndFakeQueue(final String queueName) throws Exception { SimpleString address = SimpleString.toSimpleString(queueName); clientSession.createAddress(address, RoutingType.ANYCAST, false); return new ActiveMQQueue(queueName); }
@Test(timeout = 30000) // QueueAutoCreationTest was created to validate auto-creation of queues // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238 public void testAutoCreateOnTopic() throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:5672"); Connection connection = factory.createConnection(); SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID(); System.out.println("Address is " + addressName); clientSession.createAddress(addressName, RoutingType.ANYCAST, false); Topic topic = new ActiveMQTopic(addressName.toString()); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(topic); for (int i = 0; i < 10; i++) { producer.send(session.createTextMessage("hello")); } Assert.assertTrue(((ActiveMQConnection)connection).containsKnownDestination(addressName)); }
public void deploy(TopicDeployment topicDeployment) throws Exception { if (!started) { throw new Exception("You must start() this class instance before deploying"); } String queueName = topicDeployment.getName(); boolean defaultDurable; try (ClientSession session = sessionFactory.createSession(false, false, false)) { defaultDurable = topicDeployment.isDurableSend(); ClientSession.AddressQuery query = session.addressQuery(new SimpleString(queueName)); if (!query.isExists()) session.createAddress(SimpleString.toSimpleString(queueName), RoutingType.MULTICAST, true); } destination.createTopicResource(queueName, defaultDurable, topicDeployment.getConsumerSessionTimeoutSeconds(), topicDeployment.isDuplicatesAllowed()); }
@Test //(timeout = 30000) // QueueAutoCreationTest was created to validate auto-creation of queues // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238 public void testAutoCreateOnTopic() throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory(); Connection connection = factory.createConnection(); SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID(); System.out.println("Address is " + addressName); clientSession.createAddress(addressName, RoutingType.ANYCAST, false); Topic topic = new ActiveMQTopic(addressName.toString()); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(topic); for (int i = 0; i < 10; i++) { producer.send(session.createTextMessage("hello")); } Assert.assertTrue(((ActiveMQConnection)connection).containsKnownDestination(addressName)); }
public void deploy(TopicDeployment topicDeployment) throws Exception { if (!started) { throw new Exception("You must start() this class instance before deploying"); } String queueName = topicDeployment.getName(); boolean defaultDurable; try (ClientSession session = sessionFactory.createSession(false, false, false)) { defaultDurable = topicDeployment.isDurableSend(); ClientSession.AddressQuery query = session.addressQuery(new SimpleString(queueName)); if (!query.isExists()) session.createAddress(SimpleString.toSimpleString(queueName), RoutingType.MULTICAST, true); } destination.createTopicResource(queueName, defaultDurable, topicDeployment.getConsumerSessionTimeoutSeconds(), topicDeployment.isDuplicatesAllowed()); }
@Test public void testAddressAdded() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); NotificationTest.flush(notifConsumer); session.createAddress(address, RoutingType.ANYCAST, true); ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals(ADDRESS_ADDED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertEquals(RoutingType.ANYCAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE)); Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString()); }
@Test public void testAddressRemoved() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); session.createAddress(address, RoutingType.ANYCAST, true); NotificationTest.flush(notifConsumer); server.getPostOffice().removeAddressInfo(address); ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals(ADDRESS_REMOVED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertEquals(RoutingType.ANYCAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE)); Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString()); }
@Test (timeout = 30000) // QueueAutoCreationTest was created to validate auto-creation of queues // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238 public void testAutoCreateOnAddressOnlyDuringProducerCreateQueueSucceed() throws Exception { server.getAddressSettingsRepository().clear(); AddressSettings settings = new AddressSettings().setAutoCreateAddresses(true).setAutoCreateQueues(true); server.getAddressSettingsRepository().addMatch("#", settings); ConnectionFactory factory = cf; try (Connection connection = factory.createConnection()) { SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID(); clientSession.createAddress(addressName, RoutingType.ANYCAST, true); // this will force the system to create the address only javax.jms.Queue queue = new ActiveMQQueue(addressName.toString()); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(queue); Assert.assertNotNull(server.locateQueue(addressName)); Assert.assertTrue(((ActiveMQConnection) connection).containsKnownDestination(addressName)); } }
@Test public void testGetRoutingTypesAsJSON() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); session.createAddress(address, RoutingType.ANYCAST, false); AddressControl addressControl = createManagementControl(address); JsonArray jsonArray = JsonUtil.readJsonArray(addressControl.getRoutingTypesAsJSON()); assertEquals(1, jsonArray.size()); assertEquals(RoutingType.ANYCAST.toString(), ((JsonString) jsonArray.get(0)).getString()); }
@Test public void testSendMessage() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); session.createAddress(address, RoutingType.ANYCAST, false); AddressControl addressControl = createManagementControl(address); Assert.assertEquals(0, addressControl.getQueueNames().length); session.createQueue(address, RoutingType.ANYCAST, address); Assert.assertEquals(1, addressControl.getQueueNames().length); addressControl.sendMessage(null, Message.BYTES_TYPE, Base64.encodeBytes("test".getBytes()), false, null, null); Wait.waitFor(() -> addressControl.getMessageCount() == 1); Assert.assertEquals(1, addressControl.getMessageCount()); ClientConsumer consumer = session.createConsumer(address); ClientMessage message = consumer.receive(500); assertNotNull(message); byte[] buffer = new byte[message.getBodyBuffer().readableBytes()]; message.getBodyBuffer().readBytes(buffer); assertEquals("test", new String(buffer)); }
@Test public void testAnycastMessageRoutingExclusivity() throws Exception { ClientSession sendSession = cf.createSession(false, true, true); EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST); sendSession.createAddress(addressA, routingTypes, false); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB); sendSession.createQueue(addressA, RoutingType.MULTICAST, queueC); ClientProducer p = sendSession.createProducer(addressA); ClientMessage message = sendSession.createMessage(false); message.setRoutingType(RoutingType.ANYCAST); p.send(message); sendSession.close(); assertTrue(Wait.waitFor(() -> server.locateQueue(queueA).getMessageCount() + server.locateQueue(queueB).getMessageCount() == 1)); assertTrue(Wait.waitFor(() -> server.locateQueue(queueC).getMessageCount() == 0)); }
@Test public void testMulticastMessageRoutingExclusivity() throws Exception { ClientSession sendSession = cf.createSession(false, true, true); EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST); sendSession.createAddress(addressA, routingTypes, false); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA); sendSession.createQueue(addressA, RoutingType.MULTICAST, queueB); sendSession.createQueue(addressA, RoutingType.MULTICAST, queueC); ClientProducer p = sendSession.createProducer(addressA); ClientMessage message = sendSession.createMessage(false); message.setRoutingType(RoutingType.MULTICAST); p.send(message); sendSession.close(); assertTrue(Wait.waitFor(() -> server.locateQueue(queueA).getMessageCount() == 0)); assertTrue(Wait.waitFor(() -> server.locateQueue(queueB).getMessageCount() + server.locateQueue(queueC).getMessageCount() == 2)); }
@Test public void testAmbiguousMessageRouting() throws Exception { ClientSession sendSession = cf.createSession(false, true, true); EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST); sendSession.createAddress(addressA, routingTypes, false); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB); sendSession.createQueue(addressA, RoutingType.MULTICAST, queueC); sendSession.createQueue(addressA, RoutingType.MULTICAST, queueD); ClientProducer p = sendSession.createProducer(addressA); ClientMessage message = sendSession.createMessage(false); p.send(message); sendSession.close(); assertTrue(Wait.waitFor(() -> server.locateQueue(queueA).getMessageCount() + server.locateQueue(queueB).getMessageCount() == 1)); assertTrue(Wait.waitFor(() -> server.locateQueue(queueC).getMessageCount() + server.locateQueue(queueD).getMessageCount() == 2)); } }
@Test public void testGetMessageCount() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); session.createAddress(address, RoutingType.ANYCAST, false); AddressControl addressControl = createManagementControl(address); assertEquals(0, addressControl.getMessageCount()); ClientProducer producer = session.createProducer(address.toString()); producer.send(session.createMessage(false)); assertEquals(0, addressControl.getMessageCount()); session.createQueue(address, RoutingType.ANYCAST, address); producer.send(session.createMessage(false)); assertTrue(Wait.waitFor(() -> addressControl.getMessageCount() == 1, 2000, 100)); session.createQueue(address, RoutingType.ANYCAST, address.concat('2')); producer.send(session.createMessage(false)); assertTrue(Wait.waitFor(() -> addressControl.getMessageCount() == 2, 2000, 100)); }