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

The following examples show how to use org.apache.activemq.artemis.core.settings.impl.AddressSettings#setAutoCreateAddresses() . 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: 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 3
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 4
Source File: BrokerDefinedAnycastConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testConsumeWhenNoAddressCreatedNoAutoCreate() throws Exception {
   AddressSettings settings = new AddressSettings();
   settings.setAutoCreateAddresses(false);
   server.getAddressSettingsRepository().addMatch(address.toString(), settings);
   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());
   AmqpSession session = connection.createSession();
   try {
      session.createReceiver(address.toString());
      fail("should throw exception");
   } catch (Exception e) {
      //ignore
   }
   connection.close();
}
 
Example 5
Source File: BrokerDefinedAnycastConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testConsumeWhenNoAddressCreatedAutoCreate() throws Exception {
   // This test needs auto-create.. for that just clear the settings and use defaults
   server.getAddressSettingsRepository().clear();
   AddressSettings settings = new AddressSettings();
   settings.setAutoCreateAddresses(true);
   server.getAddressSettingsRepository().addMatch(address.toString(), settings);
   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());
   AmqpSession session = connection.createSession();
   AmqpReceiver receiver = session.createReceiver(address.toString());
   sendMessages(address.toString(), 1);
   receiver.flow(1);
   AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
   assertNotNull(amqpMessage);
   assertEquals(1, ((QueueImpl)server.getPostOffice().getBinding(address).getBindable()).getConsumerCount());
   connection.close();
}
 
Example 6
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 7
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 8
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 9
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 10
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 11
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());
}