Search in sources :

Example 61 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class QueueImpl method checkRedelivery.

@Override
public boolean checkRedelivery(final MessageReference reference, final long timeBase, final boolean ignoreRedeliveryDelay) throws Exception {
    Message message = reference.getMessage();
    if (internalQueue) {
        if (logger.isTraceEnabled()) {
            logger.trace("Queue " + this.getName() + " is an internal queue, no checkRedelivery");
        }
        // no DLQ check on internal queues
        return true;
    }
    if (!internalQueue && message.isDurable() && isDurableMessage() && !reference.isPaged()) {
        storageManager.updateDeliveryCount(reference);
    }
    AddressSettings addressSettings = addressSettingsRepository.getMatch(address.toString());
    int maxDeliveries = addressSettings.getMaxDeliveryAttempts();
    long redeliveryDelay = addressSettings.getRedeliveryDelay();
    int deliveryCount = reference.getDeliveryCount();
    // First check DLA
    if (maxDeliveries > 0 && deliveryCount >= maxDeliveries) {
        if (logger.isTraceEnabled()) {
            logger.trace("Sending reference " + reference + " to DLA = " + addressSettings.getDeadLetterAddress() + " since ref.getDeliveryCount=" + reference.getDeliveryCount() + "and maxDeliveries=" + maxDeliveries + " from queue=" + this.getName());
        }
        sendToDeadLetterAddress(null, reference, addressSettings.getDeadLetterAddress());
        return false;
    } else {
        // Second check Redelivery Delay
        if (!ignoreRedeliveryDelay && redeliveryDelay > 0) {
            redeliveryDelay = calculateRedeliveryDelay(addressSettings, deliveryCount);
            if (logger.isTraceEnabled()) {
                logger.trace("Setting redeliveryDelay=" + redeliveryDelay + " on reference=" + reference);
            }
            reference.setScheduledDeliveryTime(timeBase + redeliveryDelay);
            if (!reference.isPaged() && message.isDurable() && isDurableMessage()) {
                storageManager.updateScheduledDeliveryTime(reference);
            }
        }
        decDelivering(reference);
        return true;
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Message(org.apache.activemq.artemis.api.core.Message)

Example 62 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class QueueImpl method expiryAddressFromAddressSettings.

private SimpleString expiryAddressFromAddressSettings(MessageReference ref) {
    SimpleString messageAddress = extractAddress(ref.getMessage());
    SimpleString expiryAddress = null;
    if (messageAddress != null) {
        AddressSettings addressSettings = addressSettingsRepository.getMatch(messageAddress.toString());
        expiryAddress = addressSettings.getExpiryAddress();
    }
    return expiryAddress;
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 63 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class MQTTTest method autoDestroyAddress.

@Test
public void autoDestroyAddress() throws Exception {
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setAutoDeleteAddresses(true);
    server.getAddressSettingsRepository().addMatch("foo.bar", addressSettings);
    final MQTTClientProvider subscriptionProvider = getMQTTClientProvider();
    initializeConnection(subscriptionProvider);
    subscriptionProvider.subscribe("foo/bar", AT_MOST_ONCE);
    assertNotNull(server.getAddressInfo(SimpleString.toSimpleString("foo.bar")));
    subscriptionProvider.disconnect();
    assertNull(server.getAddressInfo(SimpleString.toSimpleString("foo.bar")));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Test(org.junit.Test)

Example 64 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class SimpleOpenWireTest method testSimpleTempQueue.

@Test
public void testSimpleTempQueue() throws Exception {
    AddressSettings addressSetting = new AddressSettings();
    addressSetting.setAutoCreateQueues(true);
    addressSetting.setAutoCreateAddresses(true);
    String address = "#";
    server.getAddressSettingsRepository().addMatch(address, addressSetting);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    System.out.println("creating temp queue");
    TemporaryQueue tempQueue = session.createTemporaryQueue();
    System.out.println("create consumer 1");
    MessageConsumer consumer1 = session.createConsumer(tempQueue);
    System.out.println("create producer");
    MessageProducer producer = session.createProducer(tempQueue);
    System.out.println("sending messages");
    final int num = 1;
    final String msgBase = "MfromAMQ-";
    for (int i = 0; i < num; i++) {
        TextMessage msg = session.createTextMessage("MfromAMQ-" + i);
        producer.send(msg);
        System.out.println("Sent a message");
    }
    // receive
    System.out.println("receiving messages...");
    for (int i = 0; i < num; i++) {
        TextMessage msg = (TextMessage) consumer1.receive(5000);
        System.out.println("received: " + msg);
        String content = msg.getText();
        assertEquals(msgBase + i, content);
    }
    assertNull(consumer1.receive(500));
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) MessageConsumer(javax.jms.MessageConsumer) TemporaryQueue(javax.jms.TemporaryQueue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) XASession(javax.jms.XASession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) TopicSession(javax.jms.TopicSession) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 65 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class SimpleOpenWireTest method testAutoDestinationCreationOnProducerSend.

@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()));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) MessageConsumer(javax.jms.MessageConsumer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) XASession(javax.jms.XASession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) TopicSession(javax.jms.TopicSession) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Aggregations

AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)273 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)162 Test (org.junit.Test)161 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)103 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)103 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)88 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)65 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)54 Configuration (org.apache.activemq.artemis.core.config.Configuration)52 HashMap (java.util.HashMap)31 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)30 Queue (org.apache.activemq.artemis.core.server.Queue)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)21 Before (org.junit.Before)19 Session (javax.jms.Session)18 Message (org.apache.activemq.artemis.api.core.Message)18 ArrayList (java.util.ArrayList)15 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)14