Java Code Examples for org.apache.activemq.artemis.api.core.SimpleString#toSimpleString()
The following examples show how to use
org.apache.activemq.artemis.api.core.SimpleString#toSimpleString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProducerAutoCreateQueueTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAutoDelete() throws Exception { Connection connection = null; try { connection = factory.createConnection("admin", "password"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue trash = session.createQueue("trash"); final MessageProducer producer = session.createProducer(trash); producer.send(session.createTextMessage("foo")); Assert.assertNotNull(server.locateQueue(new SimpleString("trash"))); MessageConsumer consumer = session.createConsumer(trash); connection.start(); assertNotNull(consumer.receive(1000)); } finally { if (connection != null) { connection.close(); } } SimpleString queueName = SimpleString.toSimpleString("trash"); Wait.assertTrue(() -> server.locateQueue(queueName) == null); }
Example 2
Source File: AddressingTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testUnlimitedMaxConsumers() throws Exception { int noConsumers = 50; SimpleString address = new SimpleString("test.address"); SimpleString queueName = SimpleString.toSimpleString(UUID.randomUUID().toString()); // For each address, create 2 Queues with the same address, assert both queues receive message boolean purgeOnNoConsumers = false; Queue q1 = server.createQueue(new QueueConfiguration(queueName).setAddress(address).setMaxConsumers(Queue.MAX_CONSUMERS_UNLIMITED).setPurgeOnNoConsumers(purgeOnNoConsumers)); ClientSession session = sessionFactory.createSession(); session.start(); for (int i = 0; i < noConsumers; i++) { session.createConsumer(q1.getName()); } }
Example 3
Source File: AddressingTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testLimitOnMaxConsumers() throws Exception { SimpleString address = new SimpleString("test.address"); SimpleString queueName = SimpleString.toSimpleString(UUID.randomUUID().toString()); // For each address, create 2 Queues with the same address, assert both queues receive message boolean purgeOnNoConsumers = false; Queue q1 = server.createQueue(new QueueConfiguration(queueName).setAddress(address).setMaxConsumers(0).setPurgeOnNoConsumers(purgeOnNoConsumers)); Exception expectedException = null; String expectedMessage = "Maximum Consumer Limit Reached on Queue"; try { ClientSession session = sessionFactory.createSession(); session.start(); session.createConsumer(q1.getName()); } catch (ActiveMQQueueMaxConsumerLimitReached e) { expectedException = e; } assertNotNull(expectedException); assertTrue(expectedException.getMessage().contains(expectedMessage)); assertTrue(expectedException.getMessage().contains(address)); assertTrue(expectedException.getMessage().contains(queueName)); }
Example 4
Source File: PersistedRoles.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * @param addressMatch * @param sendRoles * @param consumeRoles * @param createDurableQueueRoles * @param deleteDurableQueueRoles * @param createNonDurableQueueRoles * @param deleteNonDurableQueueRoles * @param manageRoles * @param browseRoles * @param createAddressRoles * @param deleteAddressRoles */ public PersistedRoles(final String addressMatch, final String sendRoles, final String consumeRoles, final String createDurableQueueRoles, final String deleteDurableQueueRoles, final String createNonDurableQueueRoles, final String deleteNonDurableQueueRoles, final String manageRoles, final String browseRoles, final String createAddressRoles, final String deleteAddressRoles) { super(); this.addressMatch = SimpleString.toSimpleString(addressMatch); this.sendRoles = SimpleString.toSimpleString(sendRoles); this.consumeRoles = SimpleString.toSimpleString(consumeRoles); this.createDurableQueueRoles = SimpleString.toSimpleString(createDurableQueueRoles); this.deleteDurableQueueRoles = SimpleString.toSimpleString(deleteDurableQueueRoles); this.createNonDurableQueueRoles = SimpleString.toSimpleString(createNonDurableQueueRoles); this.deleteNonDurableQueueRoles = SimpleString.toSimpleString(deleteNonDurableQueueRoles); this.manageRoles = SimpleString.toSimpleString(manageRoles); this.browseRoles = SimpleString.toSimpleString(browseRoles); this.createAddressRoles = SimpleString.toSimpleString(createAddressRoles); this.deleteAddressRoles = SimpleString.toSimpleString(deleteAddressRoles); }
Example 5
Source File: FQQNStompTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSendFQQNMulticast() throws Exception { final SimpleString myAddress = SimpleString.toSimpleString("myAddress"); final SimpleString q1Name = SimpleString.toSimpleString("q1"); final SimpleString q2Name = SimpleString.toSimpleString("q2"); Queue q1 = server.createQueue(new QueueConfiguration(q1Name).setAddress(myAddress)); Queue q2 = server.createQueue(new QueueConfiguration(q2Name).setAddress(myAddress)); conn.connect(defUser, defPass); send(conn, myAddress + "\\c\\c" + q1Name, null, "Hello World!"); assertTrue(Wait.waitFor(() -> q1.getMessageCount() == 1, 2000, 100)); assertTrue(Wait.waitFor(() -> q2.getMessageCount() == 0, 2000, 100)); subscribeQueue(conn, "sub-01", myAddress + "\\c\\c" + q1Name); ClientStompFrame frame = conn.receiveFrame(2000); assertNotNull(frame); assertEquals("Hello World!", frame.getBody()); assertTrue(Wait.waitFor(() -> q1.getMessageCount() == 0, 2000, 100)); assertTrue(Wait.waitFor(() -> q2.getMessageCount() == 0, 2000, 100)); unsubscribe(conn, "sub-01"); }
Example 6
Source File: FQQNStompTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testReceiveFQQN2() throws Exception { final SimpleString myAddress = SimpleString.toSimpleString("myAddress"); final SimpleString q1Name = SimpleString.toSimpleString("q1"); final SimpleString q2Name = SimpleString.toSimpleString("q2"); Queue q1 = server.createQueue(new QueueConfiguration(q1Name).setAddress(myAddress)); Queue q2 = server.createQueue(new QueueConfiguration(q2Name).setAddress(myAddress)); sendJmsMessage("Hello World!", ActiveMQJMSClient.createTopic(myAddress.toString())); assertTrue(Wait.waitFor(() -> q1.getMessageCount() == 1, 2000, 100)); assertTrue(Wait.waitFor(() -> q2.getMessageCount() == 1, 2000, 100)); conn.connect(defUser, defPass); subscribeQueue(conn, "sub-01", myAddress + "\\c\\c" + q1Name); ClientStompFrame frame = conn.receiveFrame(2000); assertNotNull(frame); assertEquals("Hello World!", frame.getBody()); assertTrue(Wait.waitFor(() -> q1.getMessageCount() == 0, 2000, 100)); assertTrue(Wait.waitFor(() -> q2.getMessageCount() == 1, 2000, 100)); unsubscribe(conn, "sub-01"); }
Example 7
Source File: RetroactiveAddressTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testUpdateAfterRestart() throws Exception { final int COUNT = 10; final SimpleString addressName = SimpleString.toSimpleString("myAddress"); final SimpleString divertAnycastQueue = ResourceNames.getRetroactiveResourceQueueName(internalNamingPrefix, delimiter, addressName, RoutingType.ANYCAST); final SimpleString divertMulticastQueue = ResourceNames.getRetroactiveResourceQueueName(internalNamingPrefix, delimiter, addressName, RoutingType.MULTICAST); server.getAddressSettingsRepository().addMatch(addressName.toString(), new AddressSettings().setRetroactiveMessageCount(COUNT)); server.addAddressInfo(new AddressInfo(addressName)); Wait.assertTrue(() -> server.locateQueue(divertAnycastQueue).getRingSize() == COUNT); Wait.assertTrue(() -> server.locateQueue(divertMulticastQueue).getRingSize() == COUNT); server.stop(); server.start(); server.getAddressSettingsRepository().addMatch(addressName.toString(), new AddressSettings().setRetroactiveMessageCount(COUNT * 2)); Wait.assertTrue(() -> server.locateQueue(divertAnycastQueue).getRingSize() == COUNT * 2); Wait.assertTrue(() -> server.locateQueue(divertMulticastQueue).getRingSize() == COUNT * 2); server.getAddressSettingsRepository().addMatch(addressName.toString(), new AddressSettings().setRetroactiveMessageCount(COUNT)); Wait.assertTrue(() -> server.locateQueue(divertAnycastQueue).getRingSize() == COUNT); Wait.assertTrue(() -> server.locateQueue(divertMulticastQueue).getRingSize() == COUNT); }
Example 8
Source File: AmqpSenderRoutingTypeTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testAMQPSenderHonourRoutingTypeOfExistingAddress() throws Exception { RoutingType routingType = server.getConfiguration().getAddressesSettings().get("#").getDefaultAddressRoutingType(); Assert.assertEquals(RoutingType.ANYCAST, routingType); try (ActiveMQConnection coreConnection = (ActiveMQConnection) createCoreConnection(); ClientSession clientSession = coreConnection.getSessionFactory().createSession()) { RoutingType addressRoutingType = RoutingType.MULTICAST; SimpleString address = SimpleString.toSimpleString("myTopic_" + UUID.randomUUID().toString()); clientSession.createAddress(address, addressRoutingType, false); ClientSession.AddressQuery addressQuery = clientSession.addressQuery(address); Assert.assertTrue(addressQuery.isExists()); Assert.assertTrue(addressQuery.getQueueNames().isEmpty()); AmqpClient client = createAmqpClient(guestUser, guestPass); AmqpConnection connection = addConnection(client.connect()); AmqpSession session = connection.createSession(); AmqpSender sender = session.createSender(address.toString()); try { ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address); Assert.assertFalse(queueQuery.isExists()); Assert.assertEquals(addressRoutingType, queueQuery.getRoutingType()); } finally { sender.close(); session.close(); connection.close(); } } }
Example 9
Source File: QueueQueryTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testQueueQueryNonDefaultsOnAutoCreatedQueue() throws Exception { SimpleString queueName = SimpleString.toSimpleString(UUID.randomUUID().toString()); SimpleString lastValueKey = SimpleString.toSimpleString("myLastValueKey"); server.getAddressSettingsRepository().addMatch(queueName.toString(), new AddressSettings() .setAutoCreateAddresses(true) .setAutoCreateQueues(true) .setDefaultMaxConsumers(1) .setDefaultPurgeOnNoConsumers(true) .setDefaultConsumersBeforeDispatch(13) .setDefaultConsumerWindowSize(51) .setDefaultDelayBeforeDispatch(19L) .setDefaultLastValueQueue(true) .setDefaultLastValueKey(lastValueKey) .setDefaultExclusiveQueue(true) .setDefaultNonDestructive(true)); JMSContext c = new ActiveMQConnectionFactory("vm://0").createContext(); c.createProducer().send(c.createQueue(queueName.toString()), c.createMessage()); QueueQueryResult queueQueryResult = server.queueQuery(queueName); assertTrue(queueQueryResult.isExists()); assertEquals(RoutingType.ANYCAST, queueQueryResult.getRoutingType()); assertEquals(queueName, queueQueryResult.getName()); assertTrue(queueQueryResult.isAutoCreateQueues()); assertNull(queueQueryResult.getFilterString()); assertTrue(queueQueryResult.isAutoCreated()); assertEquals(queueName, queueQueryResult.getAddress()); assertEquals(0, queueQueryResult.getMessageCount()); // 0 since purgeOnNoConsumers = true assertEquals(0, queueQueryResult.getConsumerCount()); assertEquals(1, queueQueryResult.getMaxConsumers()); assertEquals(13, queueQueryResult.getConsumersBeforeDispatch().intValue()); assertEquals(51, queueQueryResult.getDefaultConsumerWindowSize().intValue()); assertEquals(19L, queueQueryResult.getDelayBeforeDispatch().longValue()); assertTrue(queueQueryResult.isLastValue()); assertEquals(lastValueKey, queueQueryResult.getLastValueKey()); assertTrue(queueQueryResult.isDurable()); assertTrue(queueQueryResult.isPurgeOnNoConsumers()); assertFalse(queueQueryResult.isTemporary()); assertTrue(queueQueryResult.isExclusive()); assertTrue(queueQueryResult.isNonDestructive()); }
Example 10
Source File: HQFilterConversionInterceptor.java From activemq-artemis with Apache License 2.0 | 5 votes |
private SimpleString replaceFilterString(SimpleString filterString) { if (filterString == null) { return null; } return SimpleString.toSimpleString( SelectorTranslator.convertHQToActiveMQFilterString(filterString.toString())); }
Example 11
Source File: QueueControlTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testCopiedMessageProperties() throws Exception { final String testAddress = "testAddress"; final SimpleString queue = SimpleString.toSimpleString("queue"); final int COUNT = 5; for (int i = 0; i < COUNT; i++) { server.createQueue(new QueueConfiguration(queue.concat(Integer.toString(i))).setAddress(testAddress + i).setRoutingType(RoutingType.ANYCAST)); } ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true); session.start(); ClientProducer producer = session.createProducer(new SimpleString(testAddress + "0")); ClientMessage message = session.createMessage(durable); producer.send(message); producer.close(); for (int i = 0; i < COUNT - 1; i++) { QueueControl queueControl = createManagementControl(SimpleString.toSimpleString(testAddress + i), queue.concat(Integer.toString(i)), RoutingType.ANYCAST); QueueControl otherQueueControl = createManagementControl(SimpleString.toSimpleString(testAddress + (i + 1)), queue.concat(Integer.toString(i + 1)), RoutingType.ANYCAST); assertMessageMetrics(queueControl, 1, durable); assertMessageMetrics(otherQueueControl, 0, durable); int moved = queueControl.moveMessages(null, queue.concat(Integer.toString(i + 1)).toString()); Assert.assertEquals(1, moved); assertMessageMetrics(queueControl, 0, durable); assertMessageMetrics(otherQueueControl, 1, durable); } ClientConsumer consumer1 = session.createConsumer(queue.concat(Integer.toString(COUNT - 1))); message = consumer1.receive(1000); Assert.assertNotNull(message); message.acknowledge(); System.out.println(message); Assert.assertEquals(testAddress + (COUNT - 1), message.getAddress()); Assert.assertEquals(testAddress + (COUNT - 2), message.getStringProperty(Message.HDR_ORIGINAL_ADDRESS)); }
Example 12
Source File: BridgeRoutingTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void testBridgeInternal(RoutingType sourceRoutingType, RoutingType destinationRoutingType, ComponentConfigurationRoutingType bridgeRoutingType, long sleepTime, int destinationMessageCount) throws Exception { SimpleString source = SimpleString.toSimpleString("source"); SimpleString destination = SimpleString.toSimpleString("destination"); server0.createQueue(new QueueConfiguration(source).setRoutingType(sourceRoutingType)); server1.createQueue(new QueueConfiguration(destination).setRoutingType(destinationRoutingType)); server0.deployBridge(new BridgeConfiguration() .setRoutingType(bridgeRoutingType) .setName("bridge") .setForwardingAddress(destination.toString()) .setQueueName(source.toString()) .setConfirmationWindowSize(10) .setStaticConnectors(Arrays.asList("connector"))); try (ServerLocator locator = ActiveMQClient.createServerLocator(getServer0URL()); ClientSessionFactory sessionFactory = locator.createSessionFactory(); ClientSession session = sessionFactory.createSession(); ClientProducer producer = session.createProducer(source)) { producer.send(session.createMessage(true).setRoutingType(sourceRoutingType)); } Wait.waitFor(() -> server0.locateQueue(source).getMessageCount() == 0, 2000, 100); Wait.waitFor(() -> server0.getClusterManager().getBridges().get("bridge").getMetrics().getMessagesAcknowledged() == 1, 2000, 100); Thread.sleep(sleepTime); assertTrue(Wait.waitFor(() -> server1.locateQueue(destination).getMessageCount() == destinationMessageCount, 2000, 100)); }
Example 13
Source File: ResourceAdapterTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testQueuePrefixWhenUseJndiIsFalse() throws Exception { final String prefix = "jms.queue."; final String destinationName = "test"; final SimpleString prefixedDestinationName = SimpleString.toSimpleString(prefix + destinationName); server.createQueue(new QueueConfiguration(prefixedDestinationName).setRoutingType(RoutingType.ANYCAST).setDurable(false)); ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(INVM_CONNECTOR_FACTORY); ra.start(new BootstrapContext()); Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection(); conn.close(); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(ra); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(destinationName); spec.setQueuePrefix(prefix); spec.setMaxSession(1); spec.setSetupAttempts(1); ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec); activation.start(); assertEquals(1, server.locateQueue(prefixedDestinationName).getConsumerCount()); activation.stop(); }
Example 14
Source File: RetroactiveAddressTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testMulticast() throws Exception { final String data = "Simple Text " + UUID.randomUUID().toString(); final SimpleString queueName1 = SimpleString.toSimpleString("simpleQueue1"); final SimpleString addressName = SimpleString.toSimpleString("myAddress"); final SimpleString divertQueue = ResourceNames.getRetroactiveResourceQueueName(internalNamingPrefix, delimiter, addressName, RoutingType.MULTICAST); server.getAddressSettingsRepository().addMatch(addressName.toString(), new AddressSettings().setRetroactiveMessageCount(10)); server.addAddressInfo(new AddressInfo(addressName)); ClientProducer producer = session.createProducer(addressName); ClientMessage message = session.createMessage(false); message.getBodyBuffer().writeString(data); message.setRoutingType(RoutingType.MULTICAST); producer.send(message); producer.close(); Wait.assertTrue(() -> server.locateQueue(divertQueue).getMessageCount() == 1); session.createQueue(new QueueConfiguration(queueName1).setAddress(addressName)); Wait.assertTrue(() -> server.locateQueue(queueName1) != null); Wait.assertTrue(() -> server.locateQueue(queueName1).getMessageCount() == 1); ClientConsumer consumer = session.createConsumer(queueName1); session.start(); message = consumer.receive(1000); assertNotNull(message); message.acknowledge(); assertEquals(data, message.getBodyBuffer().readString()); consumer.close(); Wait.assertTrue(() -> server.locateQueue(queueName1).getMessageCount() == 0); Wait.assertTrue(() -> server.locateQueue(divertQueue).getMessageCount() == 1); }
Example 15
Source File: AbstractFederationStream.java From activemq-artemis with Apache License 2.0 | 5 votes |
public AbstractFederationStream(final ActiveMQServer server, final Federation federation, final String name, final FederationStreamConfiguration config, final FederationConnection connection) { this.server = server; this.federation = federation; Objects.requireNonNull(config.getName()); this.name = SimpleString.toSimpleString(config.getName()); this.config = config; this.connection = connection != null ? connection : new FederationConnection(server.getConfiguration(), name, config.getConnectionConfiguration()); }
Example 16
Source File: ServerSessionImpl.java From activemq-artemis with Apache License 2.0 | 5 votes |
private RoutingStatus handleManagementMessage(final Transaction tx, final Message message, final boolean direct) throws Exception { if (AuditLogger.isEnabled()) { AuditLogger.handleManagementMessage(this.getName(), getUsername(), tx, message, direct); } try { securityCheck(removePrefix(message.getAddressSimpleString()), CheckType.MANAGE, this); } catch (ActiveMQException e) { if (!autoCommitSends) { tx.markAsRollbackOnly(e); } throw e; } Message reply = managementService.handleMessage(message); SimpleString replyTo = message.getReplyTo(); if (replyTo != null) { // TODO: move this check somewhere else? this is a JMS-specific bit of logic in the core impl if (replyTo.toString().startsWith("queue://") || replyTo.toString().startsWith("topic://")) { replyTo = SimpleString.toSimpleString(replyTo.toString().substring(8)); } else if (replyTo.toString().startsWith("temp-queue://") || replyTo.toString().startsWith("temp-topic://")) { replyTo = SimpleString.toSimpleString(replyTo.toString().substring(13)); } reply.setAddress(replyTo); doSend(tx, reply, null, direct, false, routingContext); } return RoutingStatus.OK; }
Example 17
Source File: ActiveMQProducerResource.java From activemq-artemis with Apache License 2.0 | 4 votes |
public ActiveMQProducerResource(String url, String address, String username, String password) { this(url, SimpleString.toSimpleString(address), username, password); }
Example 18
Source File: WildcardAddressManagerUnitTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
BindingFake(String addressParameter, String id) { this(SimpleString.toSimpleString(addressParameter), SimpleString.toSimpleString(id)); }
Example 19
Source File: ActiveMQDestination.java From activemq-artemis with Apache License 2.0 | 4 votes |
protected ActiveMQDestination(final String address, final String name, final TYPE type, final ActiveMQSession session) { this(SimpleString.toSimpleString(address), name, type, session); }
Example 20
Source File: AmqpReplicatedLargeMessageTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
public SimpleString getQueueName() { return SimpleString.toSimpleString("replicatedTest"); }