org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ Java Examples
The following examples show how to use
org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ.
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: EmbeddedBroker.java From cxf with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Configuration config = new ConfigurationImpl(); Set<TransportConfiguration> transports = new HashSet<>(); transports.add(new TransportConfiguration(NettyAcceptorFactory.class.getName())); transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName())); config.setAcceptorConfigurations(transports); config.setBrokerInstance(new File("target/artemis")); config.setPersistenceEnabled(false); config.setSecurityEnabled(false); config.setJMXManagementEnabled(false); EmbeddedActiveMQ server = new EmbeddedActiveMQ(); server.setConfiguration(config); server.start(); try { System.out.println("JMS broker ready ..."); Thread.sleep(125 * 60 * 1000); } finally { System.out.println("JMS broker exiting"); server.stop(); } System.exit(0); }
Example #2
Source File: ArtemisManager.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ArtemisManager( EmbeddedActiveMQ embeddedActiveMQ, ArtemisConfigData artemisConfigData ) { this.embeddedActiveMQ = embeddedActiveMQ; this.artemisConfigData = artemisConfigData; }
Example #3
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void deployBrokerConfig(EmbeddedActiveMQ server, URL configFile) throws Exception { Path brokerXML = getTestDirfile().toPath().resolve("broker.xml"); Files.copy(configFile.openStream(), brokerXML, StandardCopyOption.REPLACE_EXISTING); final ReusableLatch latch = new ReusableLatch(1); Runnable tick = latch::countDown; server.getActiveMQServer().getReloadManager().setTick(tick); latch.await(10, TimeUnit.SECONDS); }
Example #4
Source File: ActiveMQBootstrapListener.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void contextInitialized(ServletContextEvent contextEvent) { activeMQ = new EmbeddedActiveMQ(); try { activeMQ.start(); } catch (Exception e) { throw new RuntimeException(e); } }
Example #5
Source File: ArtemisTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@Override public Map<String, String> start() { try { FileUtils.deleteDirectory(Paths.get("./target/artemis").toFile()); embedded = new EmbeddedActiveMQ(); embedded.start(); } catch (Exception e) { throw new RuntimeException("Could not start embedded ActiveMQ server", e); } return Collections.emptyMap(); }
Example #6
Source File: ArtemisTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@Override public Map<String, String> start() { try { FileUtils.deleteDirectory(Paths.get("./target/artemis").toFile()); embedded = new EmbeddedActiveMQ(); embedded.start(); } catch (Exception e) { throw new RuntimeException("Could not start embedded ActiveMQ server", e); } return Collections.emptyMap(); }
Example #7
Source File: ArtemisTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@Override public Map<String, String> start() { try { FileUtils.deleteDirectory(Paths.get("./target/artemis").toFile()); embedded = new EmbeddedActiveMQ(); embedded.start(); } catch (Exception e) { throw new RuntimeException("Could not start embedded ActiveMQ server", e); } return Collections.emptyMap(); }
Example #8
Source File: ArtemisTestResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@Override public Map<String, String> start() { try { FileUtils.deleteDirectory(Paths.get("./target/artemis").toFile()); embedded = new EmbeddedActiveMQ(); embedded.start(); } catch (Exception e) { throw new RuntimeException("Could not start embedded ActiveMQ server", e); } return Collections.emptyMap(); }
Example #9
Source File: ArtemisHolder.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
void start() { try { FileUtils.deleteDirectory(Paths.get("./target/artemis").toFile()); embedded = new EmbeddedActiveMQ(); embedded.start(); } catch (Exception e) { throw new IllegalStateException("Could not start embedded ActiveMQ server", e); } }
Example #10
Source File: Async.java From javalite with Apache License 2.0 | 5 votes |
/** * Starts the server. */ public void start(){ try { artemisServer = new EmbeddedActiveMQ(); artemisServer.setConfiguration(config); artemisServer.start(); //somehow this only works after start of the server, lol. artemisServer.getActiveMQServer().getAddressSettingsRepository() .addMatch("#", new AddressSettings() .setAutoCreateQueues(false) .setAutoCreateAddresses(false) .setAutoDeleteQueues(false) .setAutoDeleteAddresses(false)); Wait.waitFor(() -> artemisServer.getActiveMQServer().isStarted()); ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://0"); consumerConnection = connectionFactory.createConnection(); receiverSessionPool = new SessionPool("Consumer", consumerConnection); producerConnection = connectionFactory.createConnection(); senderSessionPool = new SessionPool("Producer", producerConnection); configureListeners(injector, queueConfigsList); started = true; } catch (Exception e) { throw new AsyncException(e); } }
Example #11
Source File: EmbeddedActiveMQResource.java From activemq-artemis with Apache License 2.0 | 4 votes |
private void init() { if (server == null) { server = new EmbeddedActiveMQ().setConfiguration(configuration); } }
Example #12
Source File: RedeployTempTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private AddressInfo getAddressInfo(EmbeddedActiveMQ embeddedActiveMQ, String address) { return embeddedActiveMQ.getActiveMQServer().getPostOffice().getAddressInfo(SimpleString.toSimpleString(address)); }
Example #13
Source File: ArtemisJmsTest.java From a with Apache License 2.0 | 4 votes |
@BeforeClass public static void createArtemisBroker() throws Exception{ System.out.println("Starting Artemis"); broker = new EmbeddedActiveMQ(); broker.start(); }
Example #14
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private List<String> listQueuesNamesForAddress(EmbeddedActiveMQ embeddedActiveMQ, String address) throws Exception { return embeddedActiveMQ.getActiveMQServer().getPostOffice().listQueuesForAddress(SimpleString.toSimpleString(address)).stream().map( org.apache.activemq.artemis.core.server.Queue::getName).map(SimpleString::toString).collect(Collectors.toList()); }
Example #15
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private org.apache.activemq.artemis.core.server.Queue getQueue(EmbeddedActiveMQ embeddedActiveMQ, String queueName) throws Exception { QueueBinding queueBinding = (QueueBinding) embeddedActiveMQ.getActiveMQServer().getPostOffice().getBinding(SimpleString.toSimpleString(queueName)); return queueBinding == null ? null : queueBinding.getQueue(); }
Example #16
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private AddressInfo getAddressInfo(EmbeddedActiveMQ embeddedActiveMQ, String address) { return embeddedActiveMQ.getActiveMQServer().getPostOffice().getAddressInfo(SimpleString.toSimpleString(address)); }
Example #17
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private Set<Role> getSecurityRoles(EmbeddedActiveMQ embeddedActiveMQ, String address) { return embeddedActiveMQ.getActiveMQServer().getSecurityRepository().getMatch(address); }
Example #18
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private AddressSettings getAddressSettings(EmbeddedActiveMQ embeddedActiveMQ, String address) { return embeddedActiveMQ.getActiveMQServer().getAddressSettingsRepository().getMatch(address); }
Example #19
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testRedeployChangeQueueRoutingType() throws Exception { Path brokerXML = getTestDirfile().toPath().resolve("broker.xml"); URL url1 = RedeployTest.class.getClassLoader().getResource("reload-queue-routingtype.xml"); URL url2 = RedeployTest.class.getClassLoader().getResource("reload-queue-routingtype-updated.xml"); Files.copy(url1.openStream(), brokerXML); EmbeddedActiveMQ embeddedActiveMQ = new EmbeddedActiveMQ(); embeddedActiveMQ.setConfigResourcePath(brokerXML.toUri().toString()); embeddedActiveMQ.start(); final ReusableLatch latch = new ReusableLatch(1); embeddedActiveMQ.getActiveMQServer().getReloadManager().setTick(latch::countDown); try { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://0.0.0.0:61616"); try (JMSContext context = connectionFactory.createContext()) { context.createProducer().send(context.createQueue("myAddress"), "hello"); } latch.await(10, TimeUnit.SECONDS); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "myAddress")); Assert.assertEquals(RoutingType.ANYCAST, getQueue(embeddedActiveMQ, "myQueue").getRoutingType()); Files.copy(url2.openStream(), brokerXML, StandardCopyOption.REPLACE_EXISTING); brokerXML.toFile().setLastModified(System.currentTimeMillis() + 1000); latch.setCount(1); embeddedActiveMQ.getActiveMQServer().getReloadManager().setTick(latch::countDown); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "myAddress")); Assert.assertEquals(RoutingType.MULTICAST, getQueue(embeddedActiveMQ, "myQueue").getRoutingType()); //Ensures the queue isnt detroyed by checking message sent before change is consumable after (e.g. no message loss) try (JMSContext context = connectionFactory.createContext()) { Message message = context.createSharedDurableConsumer(context.createTopic("myAddress"), "myQueue").receive(); assertEquals("hello", ((TextMessage) message).getText()); } } finally { embeddedActiveMQ.stop(); } }
Example #20
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testRedeployAddressQueue() throws Exception { Path brokerXML = getTestDirfile().toPath().resolve("broker.xml"); URL url1 = RedeployTest.class.getClassLoader().getResource("reload-address-queues.xml"); URL url2 = RedeployTest.class.getClassLoader().getResource("reload-address-queues-updated.xml"); Files.copy(url1.openStream(), brokerXML); EmbeddedActiveMQ embeddedActiveMQ = new EmbeddedActiveMQ(); embeddedActiveMQ.setConfigResourcePath(brokerXML.toUri().toString()); embeddedActiveMQ.start(); final ReusableLatch latch = new ReusableLatch(1); Runnable tick = new Runnable() { @Override public void run() { latch.countDown(); } }; embeddedActiveMQ.getActiveMQServer().getReloadManager().setTick(tick); ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); try (JMSContext jmsContext = connectionFactory.createContext()) { jmsContext.createSharedDurableConsumer(jmsContext.createTopic("config_test_consumer_created_queues"),"mySub").receive(100); } try { latch.await(10, TimeUnit.SECONDS); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "config_test_consumer_created_queues").contains("mySub")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "config_test_address_removal_no_queue")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "config_test_address_removal")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "config_test_queue_removal")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "config_test_queue_removal").contains("config_test_queue_removal_queue_1")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "config_test_queue_removal").contains("config_test_queue_removal_queue_2")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "permanent_test_address_removal")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "permanent_test_queue_removal")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "permanent_test_queue_removal").contains("permanent_test_queue_removal_queue_1")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "permanent_test_queue_removal").contains("permanent_test_queue_removal_queue_2")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "config_test_queue_change")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "config_test_queue_change").contains("config_test_queue_change_queue")); Assert.assertEquals(10, getQueue(embeddedActiveMQ, "config_test_queue_change_queue").getMaxConsumers()); Assert.assertEquals(false, getQueue(embeddedActiveMQ, "config_test_queue_change_queue").isPurgeOnNoConsumers()); Files.copy(url2.openStream(), brokerXML, StandardCopyOption.REPLACE_EXISTING); brokerXML.toFile().setLastModified(System.currentTimeMillis() + 1000); latch.setCount(1); embeddedActiveMQ.getActiveMQServer().getReloadManager().setTick(tick); latch.await(10, TimeUnit.SECONDS); //Ensure queues created by clients (NOT by broker.xml are not removed when we reload). Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "config_test_consumer_created_queues").contains("mySub")); Assert.assertNull(getAddressInfo(embeddedActiveMQ, "config_test_address_removal_no_queue")); Assert.assertNull(getAddressInfo(embeddedActiveMQ, "config_test_address_removal")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "config_test_queue_removal")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "config_test_queue_removal").contains("config_test_queue_removal_queue_1")); Assert.assertFalse(listQueuesNamesForAddress(embeddedActiveMQ, "config_test_queue_removal").contains("config_test_queue_removal_queue_2")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "permanent_test_address_removal")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "permanent_test_queue_removal")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "permanent_test_queue_removal").contains("permanent_test_queue_removal_queue_1")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "permanent_test_queue_removal").contains("permanent_test_queue_removal_queue_2")); Assert.assertNotNull(getAddressInfo(embeddedActiveMQ, "config_test_queue_change")); Assert.assertTrue(listQueuesNamesForAddress(embeddedActiveMQ, "config_test_queue_change").contains("config_test_queue_change_queue")); Assert.assertEquals(1, getQueue(embeddedActiveMQ, "config_test_queue_change_queue").getMaxConsumers()); Assert.assertEquals(true, getQueue(embeddedActiveMQ, "config_test_queue_change_queue").isPurgeOnNoConsumers()); Assert.assertNull(getAddressInfo(embeddedActiveMQ, "config_test_queue_change_queue")); Assert.assertNull(getAddressInfo(embeddedActiveMQ, "config_test_queue_removal_queue_1")); } finally { embeddedActiveMQ.stop(); } }
Example #21
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testRedeployQueueDefaults() throws Exception { Path brokerXML = getTestDirfile().toPath().resolve("broker.xml"); URL baseConfig = RedeployTest.class.getClassLoader().getResource("reload-queue-defaults-before.xml"); URL newConfig = RedeployTest.class.getClassLoader().getResource("reload-queue-defaults-after.xml"); Files.copy(baseConfig.openStream(), brokerXML, StandardCopyOption.REPLACE_EXISTING); EmbeddedActiveMQ embeddedActiveMQ = new EmbeddedActiveMQ(); embeddedActiveMQ.setConfigResourcePath(brokerXML.toUri().toString()); embeddedActiveMQ.start(); try { LocalQueueBinding queueBinding = (LocalQueueBinding) embeddedActiveMQ.getActiveMQServer().getPostOffice() .getBinding(new SimpleString("myQueue")); org.apache.activemq.artemis.core.server.Queue queue = queueBinding.getQueue(); assertNotEquals(queue.getMaxConsumers(), ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()); assertNotEquals(queue.getRoutingType(), RoutingType.MULTICAST); assertNotEquals(queue.isPurgeOnNoConsumers(), ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers()); assertNotEquals(queue.isEnabled(), ActiveMQDefaultConfiguration.getDefaultEnabled()); assertNotEquals(queue.isExclusive(), ActiveMQDefaultConfiguration.getDefaultExclusive()); assertNotEquals(queue.isGroupRebalance(), ActiveMQDefaultConfiguration.getDefaultGroupRebalance()); assertNotEquals(queue.getGroupBuckets(), ActiveMQDefaultConfiguration.getDefaultGroupBuckets()); assertNotEquals(queue.getGroupFirstKey(), ActiveMQDefaultConfiguration.getDefaultGroupFirstKey()); assertNotEquals(queue.isNonDestructive(), ActiveMQDefaultConfiguration.getDefaultNonDestructive()); assertNotEquals(queue.getConsumersBeforeDispatch(), ActiveMQDefaultConfiguration.getDefaultConsumersBeforeDispatch()); assertNotEquals(queue.getDelayBeforeDispatch(), ActiveMQDefaultConfiguration.getDefaultDelayBeforeDispatch()); assertNotEquals(queue.getFilter(), null); assertNotEquals(queue.getUser(), "jdoe"); assertNotEquals(queue.getRingSize(), ActiveMQDefaultConfiguration.getDefaultRingSize()); deployBrokerConfig(embeddedActiveMQ, newConfig); assertEquals(queue.getMaxConsumers(), ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()); assertEquals(queue.getRoutingType(), RoutingType.MULTICAST); assertEquals(queue.isPurgeOnNoConsumers(), ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers()); assertEquals(queue.isEnabled(), ActiveMQDefaultConfiguration.getDefaultEnabled()); assertEquals(queue.isExclusive(), ActiveMQDefaultConfiguration.getDefaultExclusive()); assertEquals(queue.isGroupRebalance(), ActiveMQDefaultConfiguration.getDefaultGroupRebalance()); assertEquals(queue.getGroupBuckets(), ActiveMQDefaultConfiguration.getDefaultGroupBuckets()); assertEquals(queue.getGroupFirstKey(), ActiveMQDefaultConfiguration.getDefaultGroupFirstKey()); assertEquals(queue.isNonDestructive(), ActiveMQDefaultConfiguration.getDefaultNonDestructive()); assertEquals(queue.getConsumersBeforeDispatch(), ActiveMQDefaultConfiguration.getDefaultConsumersBeforeDispatch()); assertEquals(queue.getDelayBeforeDispatch(), ActiveMQDefaultConfiguration.getDefaultDelayBeforeDispatch()); assertEquals(queue.getFilter(), null); assertEquals(queue.getUser(), null); assertEquals(queue.getRingSize(), ActiveMQDefaultConfiguration.getDefaultRingSize()); } finally { embeddedActiveMQ.stop(); } }
Example #22
Source File: RedeployTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testRedeploy() throws Exception { Path brokerXML = getTestDirfile().toPath().resolve("broker.xml"); URL url1 = RedeployTest.class.getClassLoader().getResource("reload-test-jms.xml"); URL url2 = RedeployTest.class.getClassLoader().getResource("reload-test-updated-jms.xml"); Files.copy(url1.openStream(), brokerXML); EmbeddedActiveMQ embeddedActiveMQ = new EmbeddedActiveMQ(); embeddedActiveMQ.setConfigResourcePath(brokerXML.toUri().toString()); embeddedActiveMQ.start(); final ReusableLatch latch = new ReusableLatch(1); Runnable tick = new Runnable() { @Override public void run() { latch.countDown(); } }; embeddedActiveMQ.getActiveMQServer().getReloadManager().setTick(tick); try { latch.await(10, TimeUnit.SECONDS); Assert.assertEquals("DLQ", embeddedActiveMQ.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getDeadLetterAddress().toString()); Assert.assertEquals("ExpiryQueue", embeddedActiveMQ.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getExpiryAddress().toString()); Assert.assertFalse(tryConsume()); Files.copy(url2.openStream(), brokerXML, StandardCopyOption.REPLACE_EXISTING); brokerXML.toFile().setLastModified(System.currentTimeMillis() + 1000); latch.setCount(1); embeddedActiveMQ.getActiveMQServer().getReloadManager().setTick(tick); latch.await(10, TimeUnit.SECONDS); Assert.assertTrue(tryConsume()); Assert.assertEquals("NewQueue", embeddedActiveMQ.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getDeadLetterAddress().toString()); Assert.assertEquals("NewQueue", embeddedActiveMQ.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getExpiryAddress().toString()); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); try (Connection connection = factory.createConnection()) { Session session = connection.createSession(); Queue queue = session.createQueue("DivertQueue"); MessageProducer producer = session.createProducer(queue); producer.send(session.createTextMessage("text")); connection.start(); MessageConsumer consumer = session.createConsumer(session.createQueue("NewQueue")); Assert.assertNotNull("Divert wasn't redeployed accordingly", consumer.receive(5000)); } } finally { embeddedActiveMQ.stop(); } }
Example #23
Source File: RedeployTempTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private List<String> listQueuesNamesForAddress(EmbeddedActiveMQ embeddedActiveMQ, String address) throws Exception { return embeddedActiveMQ.getActiveMQServer().getPostOffice().listQueuesForAddress(SimpleString.toSimpleString(address)).stream().map(org.apache.activemq.artemis.core.server.Queue::getName).map(SimpleString::toString).collect(Collectors.toList()); }
Example #24
Source File: RedeployTempTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private org.apache.activemq.artemis.core.server.Queue getQueue(EmbeddedActiveMQ embeddedActiveMQ, String queueName) throws Exception { QueueBinding queueBinding = (QueueBinding) embeddedActiveMQ.getActiveMQServer().getPostOffice().getBinding(SimpleString.toSimpleString(queueName)); return queueBinding == null ? null : queueBinding.getQueue(); }
Example #25
Source File: MessagesManager.java From vertx-spring-boot with Apache License 2.0 | 4 votes |
public MessagesManager(AmqpClient client, EmbeddedActiveMQ server) { this.client = client; }
Example #26
Source File: RedeployTempTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private Set<Role> getSecurityRoles(EmbeddedActiveMQ embeddedActiveMQ, String address) { return embeddedActiveMQ.getActiveMQServer().getSecurityRepository().getMatch(address); }
Example #27
Source File: RedeployTempTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
private AddressSettings getAddressSettings(EmbeddedActiveMQ embeddedActiveMQ, String address) { return embeddedActiveMQ.getActiveMQServer().getAddressSettingsRepository().getMatch(address); }
Example #28
Source File: RedeployTempTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testRedeployAddressQueueOpenWire() throws Exception { Path brokerXML = getTestDirfile().toPath().resolve("broker.xml"); URL url1 = RedeployTest.class.getClassLoader().getResource("RedeployTempTest-reload-temp.xml"); URL url2 = RedeployTest.class.getClassLoader().getResource("RedeployTempTest-reload-temp-updated.xml"); Files.copy(url1.openStream(), brokerXML); EmbeddedActiveMQ embeddedActiveMQ = new EmbeddedActiveMQ(); embeddedActiveMQ.setConfigResourcePath(brokerXML.toUri().toString()); embeddedActiveMQ.start(); final ReusableLatch latch = new ReusableLatch(1); Runnable tick = latch::countDown; embeddedActiveMQ.getActiveMQServer().getReloadManager().setTick(tick); ConnectionFactory connectionFactory = new org.apache.activemq.ActiveMQConnectionFactory(); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue("queue"); MessageProducer messageProducer = session.createProducer(destination); Destination replyTo = session.createTemporaryQueue(); Message message = session.createTextMessage("hello"); message.setJMSReplyTo(replyTo); messageProducer.send(message); try { latch.await(10, TimeUnit.SECONDS); Files.copy(url2.openStream(), brokerXML, StandardCopyOption.REPLACE_EXISTING); brokerXML.toFile().setLastModified(System.currentTimeMillis() + 1000); latch.setCount(1); embeddedActiveMQ.getActiveMQServer().getReloadManager().setTick(tick); latch.await(10, TimeUnit.SECONDS); try (Connection connectionConsumer = connectionFactory.createConnection()) { connectionConsumer.start(); try (Session sessionConsumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) { Destination destinationConsumer = session.createQueue("queue"); MessageConsumer messageConsumer = sessionConsumer.createConsumer(destinationConsumer); Message receivedMessage = messageConsumer.receive(1000); assertEquals("hello", ((TextMessage) receivedMessage).getText()); Destination replyToDest = receivedMessage.getJMSReplyTo(); Message message1 = sessionConsumer.createTextMessage("hi there"); session.createProducer(replyToDest).send(message1); } } MessageConsumer messageConsumerProducer = session.createConsumer(replyTo); Message message2 = messageConsumerProducer.receive(1000); Assert.assertNotNull(message2); assertEquals("hi there", ((TextMessage) message2).getText()); } finally { connection.close(); embeddedActiveMQ.stop(); } }
Example #29
Source File: EmbeddedRestActiveMQ.java From activemq-artemis with Apache License 2.0 | 4 votes |
public void setEmbeddedActiveMQ(EmbeddedActiveMQ embeddedActiveMQ) { this.embeddedActiveMQ = embeddedActiveMQ; }
Example #30
Source File: EmbeddedRestActiveMQ.java From activemq-artemis with Apache License 2.0 | 4 votes |
public EmbeddedActiveMQ getEmbeddedActiveMQ() { return embeddedActiveMQ; }