Java Code Examples for org.apache.activemq.artemis.core.server.ActiveMQServer#deployDivert()
The following examples show how to use
org.apache.activemq.artemis.core.server.ActiveMQServer#deployDivert() .
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: DivertTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testInjectedTransformer() throws Exception { final SimpleString ADDRESS = new SimpleString("myAddress"); final String DIVERT = "myDivert"; ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl(); Transformer transformer = new Transformer() { @Override public Message transform(Message message) { return null; } }; serviceRegistry.addDivertTransformer(DIVERT, transformer); ActiveMQServer server = addServer(new ActiveMQServerImpl(createBasicConfig(), null, null, null, serviceRegistry)); server.start(); server.waitForActivation(100, TimeUnit.MILLISECONDS); server.createQueue(new QueueConfiguration("myQueue").setAddress(ADDRESS).setDurable(false)); server.deployDivert(new DivertConfiguration().setName(DIVERT).setAddress(ADDRESS.toString()).setForwardingAddress(ADDRESS.toString())); Collection<Binding> bindings = server.getPostOffice().getBindingsForAddress(ADDRESS).getBindings(); Divert divert = null; for (Binding binding : bindings) { if (binding instanceof DivertBinding) { divert = ((DivertBinding) binding).getDivert(); } } assertNotNull(divert); assertEquals(transformer, divert.getTransformer()); server.destroyDivert(SimpleString.toSimpleString(DIVERT)); assertNull(serviceRegistry.getDivertTransformer(DIVERT, null)); }
Example 2
Source File: DivertTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testProperties() throws Exception { final String testAddress = "testAddress"; final SimpleString queue = SimpleString.toSimpleString("queue"); final int COUNT = 25; ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), false)); server.start(); server.createQueue(new QueueConfiguration(queue).setAddress(testAddress + (COUNT)).setRoutingType(RoutingType.ANYCAST)); for (int i = 0; i < COUNT; i++) { server.deployDivert(new DivertConfiguration() .setName("divert" + i) .setAddress(testAddress + i) .setForwardingAddress(testAddress + (i + 1))); } ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true); session.start(); ClientProducer producer = session.createProducer(new SimpleString(testAddress + "0")); ClientConsumer consumer1 = session.createConsumer(queue); ClientMessage message = session.createMessage(false); producer.send(message); message = consumer1.receive(DivertTest.TIMEOUT); Assert.assertNotNull(message); message.acknowledge(); Assert.assertEquals("testAddress" + COUNT, message.getAddress()); Assert.assertEquals("testAddress" + (COUNT - 1), message.getStringProperty(Message.HDR_ORIGINAL_ADDRESS)); }
Example 3
Source File: LargeMessageTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testDivertAndExpire() throws Exception { final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE); final String DIVERTED = "diverted"; ClientSession session = null; ActiveMQServer server = createServer(true, isNetty(), storeType); server.getConfiguration().setMessageExpiryScanPeriod(100); server.start(); server.createQueue(new QueueConfiguration(DIVERTED)); server.getAddressSettingsRepository().addMatch(DIVERTED, new AddressSettings().setExpiryDelay(250L).setExpiryAddress(SimpleString.toSimpleString(DIVERTED + "Expiry")).setAutoCreateExpiryResources(true)); server.deployDivert(new DivertConfiguration().setName("myDivert").setAddress(ADDRESS.toString()).setForwardingAddress(DIVERTED).setExclusive(true)); ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator)); session = addClientSession(sf.createSession(false, false, false)); session.createQueue(new QueueConfiguration(ADDRESS).setDurable(false).setTemporary(true)); ClientProducer producer = session.createProducer(ADDRESS); Message clientFile = createLargeClientMessageStreaming(session, messageSize, true); producer.send(clientFile); session.commit(); session.start(); Wait.waitFor(() -> server.locateQueue(AddressSettings.DEFAULT_EXPIRY_QUEUE_PREFIX + DIVERTED) != null, 1000, 100); ClientConsumer consumer = session.createConsumer(AddressSettings.DEFAULT_EXPIRY_QUEUE_PREFIX + DIVERTED); ClientMessage msg1 = consumer.receive(1000); msg1.acknowledge(); session.commit(); Assert.assertNotNull(msg1); consumer.close(); try { msg1.getBodyBuffer().readByte(); Assert.fail("Exception was expected"); } catch (final Exception ignored) { // empty on purpose } session.close(); validateNoFilesOnLargeDir(); }