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;
}
}
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;
}
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")));
}
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();
}
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()));
}
Aggregations