Java Code Examples for org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ#start()

The following examples show how to use org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ#start() . 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 vote down vote up
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: ArtemisHolder.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
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 3
Source File: ArtemisTestResource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: ArtemisTestResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: ArtemisTestResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@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 vote down vote up
@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: ActiveMQBootstrapListener.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
   activeMQ = new EmbeddedActiveMQ();
   try {
      activeMQ.start();
   } catch (Exception e) {
      throw new RuntimeException(e);
   }
}
 
Example 8
Source File: Async.java    From javalite with Apache License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: RedeployTempTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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 10
Source File: RedeployTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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 11
Source File: RedeployTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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 12
Source File: RedeployTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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 13
Source File: RedeployTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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 14
Source File: ArtemisJmsTest.java    From a with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void createArtemisBroker() throws Exception{
   System.out.println("Starting Artemis");
   broker = new EmbeddedActiveMQ();
   broker.start();
}