Java Code Examples for org.apache.activemq.artemis.core.settings.impl.AddressSettings#setAutoCreateQueues()

The following examples show how to use org.apache.activemq.artemis.core.settings.impl.AddressSettings#setAutoCreateQueues() . 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: SimpleOpenWireTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoDestinationCreationOnProducerSend() throws JMSException {
   AddressSettings addressSetting = new AddressSettings();
   addressSetting.setAutoCreateQueues(true);
   addressSetting.setAutoCreateAddresses(true);

   String address = "foo";
   server.getAddressSettingsRepository().addMatch(address, addressSetting);

   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   TextMessage message = session.createTextMessage("bar");
   Queue queue = new ActiveMQQueue(address);

   MessageProducer producer = session.createProducer(null);
   producer.send(queue, message);

   MessageConsumer consumer = session.createConsumer(queue);
   TextMessage message1 = (TextMessage) consumer.receive(1000);
   assertTrue(message1.getText().equals(message.getText()));
}
 
Example 2
Source File: SimpleOpenWireTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoDestinationNoCreationOnConsumer() throws JMSException {
   AddressSettings addressSetting = new AddressSettings();
   addressSetting.setAutoCreateQueues(false);

   String address = "foo";
   server.getAddressSettingsRepository().addMatch(address, addressSetting);

   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   TextMessage message = session.createTextMessage("bar");
   Queue queue = new ActiveMQQueue(address);

   try {
      MessageConsumer consumer = session.createConsumer(queue);
      fail("supposed to throw an exception here");
   } catch (JMSException e) {

   }
}
 
Example 3
Source File: JMSMessageGroupsTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureAddressPolicy(ActiveMQServer server) {
   super.configureAddressPolicy(server);

   AddressSettings addressSettings = new AddressSettings();

   addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
   addressSettings.setAutoCreateQueues(isAutoCreateQueues());
   addressSettings.setAutoCreateAddresses(isAutoCreateAddresses());
   addressSettings.setDeadLetterAddress(SimpleString.toSimpleString(getDeadLetterAddress()));
   addressSettings.setExpiryAddress(SimpleString.toSimpleString(getDeadLetterAddress()));
   addressSettings.setDefaultGroupFirstKey(SimpleString.toSimpleString("JMSXFirstInGroupID"));


   server.getConfiguration().getAddressesSettings().put("GroupFirst.#", addressSettings);
}
 
Example 4
Source File: AmqpClientTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void configureAddressPolicy(ActiveMQServer server) {
   // Address configuration
   AddressSettings addressSettings = new AddressSettings();

   addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
   addressSettings.setAutoCreateQueues(isAutoCreateQueues());
   addressSettings.setAutoCreateAddresses(isAutoCreateAddresses());
   addressSettings.setDeadLetterAddress(SimpleString.toSimpleString(getDeadLetterAddress()));
   addressSettings.setExpiryAddress(SimpleString.toSimpleString(getDeadLetterAddress()));

   server.getConfiguration().getAddressesSettings().put("#", addressSettings);
   Set<TransportConfiguration> acceptors = server.getConfiguration().getAcceptorConfigurations();
   for (TransportConfiguration tc : acceptors) {
      if (tc.getName().equals("netty-acceptor")) {
         tc.getExtraParams().put("anycastPrefix", "anycast://");
         tc.getExtraParams().put("multicastPrefix", "multicast://");
      }
   }
}
 
Example 5
Source File: SessionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateQueueWhileTopicWithSameNameExists() throws Exception {
   AddressSettings addressSettings = new AddressSettings();
   addressSettings.setAutoCreateQueues(false);
   addressSettings.setAutoCreateAddresses(false);
   getJmsServer().getAddressSettingsRepository().addMatch("#", addressSettings);

   Connection conn = getConnectionFactory().createConnection();
   Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   try {
      sess.createQueue("TestTopic");
      ProxyAssertSupport.fail("should throw JMSException");
   } catch (JMSException e) {
      // OK
   }
   conn.close();
}
 
Example 6
Source File: SimpleOpenWireTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAutoDestinationCreationAndDeletionOnConsumer() throws Exception {
   AddressSettings addressSetting = new AddressSettings();
   addressSetting.setAutoCreateQueues(true);
   addressSetting.setAutoCreateAddresses(true);
   addressSetting.setAutoDeleteQueues(true);
   addressSetting.setAutoDeleteAddresses(true);

   String address = "foo";
   server.getAddressSettingsRepository().addMatch(address, addressSetting);

   connection.start();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   TextMessage message = session.createTextMessage("bar");
   Queue queue = new ActiveMQQueue(address);

   MessageConsumer consumer = session.createConsumer(queue);

   assertTrue(Wait.waitFor(() -> (server.locateQueue(SimpleString.toSimpleString("foo")) != null), 2000, 100));
   assertTrue(Wait.waitFor(() -> (server.getAddressInfo(SimpleString.toSimpleString("foo")) != null), 2000, 100));

   MessageProducer producer = session.createProducer(null);
   producer.send(queue, message);

   TextMessage message1 = (TextMessage) consumer.receive(1000);
   assertTrue(message1.getText().equals(message.getText()));

   assertNotNull(server.locateQueue(SimpleString.toSimpleString("foo")));

   consumer.close();
   connection.close();

   assertTrue(Wait.waitFor(() -> (server.locateQueue(SimpleString.toSimpleString("foo")) == null), 2000, 100));
   assertTrue(Wait.waitFor(() -> (server.getAddressInfo(SimpleString.toSimpleString("foo")) == null), 2000, 100));
}
 
Example 7
Source File: LargeMessageQueueAutoCreationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void extraServerConfig(Configuration serverConfig) {
   serverConfig.setJournalType(JournalType.NIO);
   Map<String, AddressSettings> map = serverConfig.getAddressesSettings();
   Map.Entry<String, AddressSettings> entry = map.entrySet().iterator().next();
   AddressSettings settings = entry.getValue();
   settings.setAutoCreateQueues(true);
}
 
Example 8
Source File: JmsDurableQueueWildcardSendReceiveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void extraServerConfig(Configuration serverConfig) {
   AddressSettings settings = serverConfig.getAddressesSettings().get("#");
   if (settings != null) {
      settings.setAutoCreateQueues(true);
   }
}
 
Example 9
Source File: AmqpReceiverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testLinkDetatchErrorIsCorrectWhenQueueDoesNotExists() throws Exception {
   AddressSettings value = new AddressSettings();
   value.setAutoCreateQueues(false);
   value.setAutoCreateAddresses(false);
   server.getAddressSettingsRepository().addMatch("AnAddressThatDoesNotExist", value);

   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());

   try {
      AmqpSession session = connection.createSession();

      Exception expectedException = null;
      try {
         session.createSender("AnAddressThatDoesNotExist");
         fail("Creating a sender here on an address that doesn't exist should fail");
      } catch (Exception e) {
         expectedException = e;
      }

      assertNotNull(expectedException);
      assertTrue(expectedException.getMessage().contains("amqp:not-found"));
      assertTrue(expectedException.getMessage().contains("target address does not exist"));
   } finally {
      connection.close();
   }
}
 
Example 10
Source File: QueueAutoCreationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureAddressPolicy(ActiveMQServer server) {
   Configuration serverConfig = server.getConfiguration();
   serverConfig.setJournalType(JournalType.NIO);
   Map<String, AddressSettings> map = serverConfig.getAddressesSettings();
   if (map.size() == 0) {
      AddressSettings as = new AddressSettings();
      map.put("#", as);
   }
   Map.Entry<String, AddressSettings> entry = map.entrySet().iterator().next();
   AddressSettings settings = entry.getValue();
   settings.setAutoCreateQueues(true);
   instanceLog.debug("server cofg, isauto? " + entry.getValue().isAutoCreateQueues());
}
 
Example 11
Source File: DLQAfterExpiredMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureAddressPolicy(ActiveMQServer server) {
   // Address configuration
   AddressSettings addressSettings = new AddressSettings();

   addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
   addressSettings.setAutoCreateQueues(isAutoCreateQueues());
   addressSettings.setAutoCreateAddresses(isAutoCreateAddresses());
   addressSettings.setDeadLetterAddress(SimpleString.toSimpleString(getDeadLetterAddress()));
   addressSettings.setExpiryAddress(SimpleString.toSimpleString(getExpiryQueue()));
   addressSettings.setMaxDeliveryAttempts(1);
   server.getConfiguration().getAddressesSettings().put("#", addressSettings);
   server.getConfiguration().getAddressesSettings().put(getExpiryQueue(), addressSettings);
}
 
Example 12
Source File: MQTTTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void configureBroker() throws Exception {
   // TODO Add SSL
   super.setUp();
   server = createServerForMQTT();
   addCoreConnector();
   addMQTTConnector();
   AddressSettings addressSettings = new AddressSettings();
   addressSettings.setMaxSizeBytes(999999999);
   addressSettings.setAutoCreateQueues(true);
   addressSettings.setAutoCreateAddresses(true);
   configureBrokerSecurity(server);

   server.getAddressSettingsRepository().addMatch("#", addressSettings);
}
 
Example 13
Source File: SessionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateNonExistentQueue() throws Exception {
   AddressSettings addressSettings = new AddressSettings();
   addressSettings.setAutoCreateQueues(false);
   getJmsServer().getAddressSettingsRepository().addMatch("#", addressSettings);

   Connection conn = getConnectionFactory().createConnection();
   Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   try {
      sess.createQueue("QueueThatDoesNotExist");
      ProxyAssertSupport.fail();
   } catch (JMSException e) {
   }
   conn.close();
}
 
Example 14
Source File: StompV12Test.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testHeaderRepetitive() throws Exception {
   AddressSettings addressSettings = new AddressSettings();
   addressSettings.setAutoCreateQueues(false);
   addressSettings.setAutoCreateAddresses(false);
   server.getAddressSettingsRepository().addMatch("#", addressSettings);

   conn.connect(defUser, defPass);

   String body = "Hello World!";
   String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);

   ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND)
                                .addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName())
                                .addHeader(Stomp.Headers.Subscribe.DESTINATION, "aNonexistentQueue")
                                .addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml")
                                .addHeader(Stomp.Headers.CONTENT_LENGTH, cLen)
                                .addHeader("foo", "value1")
                                .addHeader("foo", "value2")
                                .addHeader("foo", "value3");

   frame.setBody(body);

   conn.sendFrame(frame);

   //subscribe
   StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
   newConn.connect(defUser, defPass);
   subscribe(newConn, "a-sub", null, null, true);

   frame = newConn.receiveFrame();

   Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
   Assert.assertEquals(body, frame.getBody());

   instanceLog.debug("received: " + frame);
   Assert.assertEquals("value1", frame.getHeader("foo"));

   //unsub
   unsubscribe(newConn, "a-sub", true);

   newConn.disconnect();

   //should get error

   body = "Hello World!";
   cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);

   frame = conn.createFrame(Stomp.Commands.SEND)
               .addHeader(Stomp.Headers.Subscribe.DESTINATION, "aNonexistentQueue")
               .addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName())
               .addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml")
               .addHeader(Stomp.Headers.CONTENT_LENGTH, cLen)
               .addHeader(Stomp.Headers.RECEIPT_REQUESTED, "1234")
               .setBody(body);

   ClientStompFrame reply = conn.sendFrame(frame);
   // TODO this is broken because queue auto-creation is always on
   Assert.assertEquals(Stomp.Responses.ERROR, reply.getCommand());
}