use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class MessageExpirationTest method testMessageExpiredWithExpiryAddress.
@Test
public void testMessageExpiredWithExpiryAddress() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
final SimpleString expiryAddress = RandomUtil.randomSimpleString();
SimpleString expiryQueue = RandomUtil.randomSimpleString();
server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings() {
private static final long serialVersionUID = -6476053400596299130L;
@Override
public SimpleString getExpiryAddress() {
return expiryAddress;
}
});
session.createQueue(address, queue, false);
session.createQueue(expiryAddress, expiryQueue, false);
ClientProducer producer = session.createProducer(address);
ClientMessage message = session.createMessage(false);
message.setExpiration(System.currentTimeMillis() + MessageExpirationTest.EXPIRATION);
producer.send(message);
Thread.sleep(MessageExpirationTest.EXPIRATION * 2);
session.start();
ClientConsumer consumer = session.createConsumer(queue);
ClientMessage message2 = consumer.receiveImmediate();
Assert.assertNull(message2);
ClientConsumer expiryConsumer = session.createConsumer(expiryQueue);
ClientMessage expiredMessage = expiryConsumer.receive(500);
Assert.assertNotNull(expiredMessage);
Assert.assertNotNull(expiredMessage.getObjectProperty(Message.HDR_ACTUAL_EXPIRY_TIME));
Assert.assertEquals(address, expiredMessage.getObjectProperty(Message.HDR_ORIGINAL_ADDRESS));
Assert.assertEquals(queue, expiredMessage.getObjectProperty(Message.HDR_ORIGINAL_QUEUE));
consumer.close();
expiryConsumer.close();
session.deleteQueue(queue);
session.deleteQueue(expiryQueue);
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class ProducerFlowControlTest method testFlowControlMessageNotRouted.
@Test
public void testFlowControlMessageNotRouted() throws Exception {
final SimpleString address = new SimpleString("testaddress");
server = createServer(false, isNetty());
AddressSettings addressSettings = new AddressSettings().setMaxSizeBytes(1024).setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
repos.addMatch(address.toString(), addressSettings);
server.start();
waitForServerToStart(server);
locator.setProducerWindowSize(1024).setConsumerWindowSize(1024).setAckBatchSize(1024);
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, true);
ClientProducer producer = session.createProducer(address);
byte[] bytes = new byte[100];
final int numMessages = 1000;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(false);
message.getBodyBuffer().writeBytes(bytes);
producer.send(message);
}
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class ProducerFlowControlTest method testFlowControl.
private void testFlowControl(final int numMessages, final int messageSize, final int maxSize, final int producerWindowSize, final int consumerWindowSize, final int ackBatchSize, final int numConsumers, final int numProducers, final long consumerDelay, final boolean anon, final int minLargeMessageSize, final boolean realFiles) throws Exception {
final SimpleString address = new SimpleString("testaddress");
server = createServer(realFiles, isNetty());
AddressSettings addressSettings = new AddressSettings().setMaxSizeBytes(maxSize).setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
repos.addMatch(address.toString(), addressSettings);
server.start();
waitForServerToStart(server);
locator.setProducerWindowSize(producerWindowSize).setConsumerWindowSize(consumerWindowSize).setAckBatchSize(ackBatchSize);
if (minLargeMessageSize != -1) {
locator.setMinLargeMessageSize(minLargeMessageSize);
}
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, true);
session.start();
final String queueName = "testqueue";
for (int i = 0; i < numConsumers; i++) {
session.createQueue(address, new SimpleString(queueName + i), null, false);
}
final byte[] bytes = RandomUtil.randomBytes(messageSize);
class MyHandler implements MessageHandler {
int count = 0;
final CountDownLatch latch = new CountDownLatch(1);
volatile Exception exception;
@Override
public void onMessage(final ClientMessage message) {
try {
byte[] bytesRead = new byte[messageSize];
message.getBodyBuffer().readBytes(bytesRead);
ActiveMQTestBase.assertEqualsByteArrays(bytes, bytesRead);
message.acknowledge();
if (++count == numMessages * numProducers) {
latch.countDown();
}
if (consumerDelay > 0) {
Thread.sleep(consumerDelay);
}
} catch (Exception e) {
ProducerFlowControlTest.log.error("Failed to handle message", e);
exception = e;
latch.countDown();
}
}
}
MyHandler[] handlers = new MyHandler[numConsumers];
for (int i = 0; i < numConsumers; i++) {
handlers[i] = new MyHandler();
ClientConsumer consumer = session.createConsumer(new SimpleString(queueName + i));
consumer.setMessageHandler(handlers[i]);
}
ClientProducer[] producers = new ClientProducer[numProducers];
for (int i = 0; i < numProducers; i++) {
if (anon) {
producers[i] = session.createProducer();
} else {
producers[i] = session.createProducer(address);
}
}
long start = System.currentTimeMillis();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(false);
message.getBodyBuffer().writeBytes(bytes);
for (int j = 0; j < numProducers; j++) {
if (anon) {
producers[j].send(address, message);
} else {
producers[j].send(message);
}
}
}
for (int i = 0; i < numConsumers; i++) {
Assert.assertTrue(handlers[i].latch.await(5, TimeUnit.MINUTES));
Assert.assertNull(handlers[i].exception);
}
long end = System.currentTimeMillis();
double rate = 1000 * (double) numMessages / (end - start);
ProducerFlowControlTest.log.info("rate is " + rate + " msgs / sec");
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class ProducerFlowControlTest method testClosingSessionUnblocksBlockedProducer.
@Test
public void testClosingSessionUnblocksBlockedProducer() throws Exception {
final SimpleString address = new SimpleString("testaddress");
server = createServer(false, isNetty());
AddressSettings addressSettings = new AddressSettings().setMaxSizeBytes(1024).setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
repos.addMatch(address.toString(), addressSettings);
server.start();
waitForServerToStart(server);
locator.setProducerWindowSize(1024).setConsumerWindowSize(1024).setAckBatchSize(1024);
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, true);
final SimpleString queueName = new SimpleString("testqueue");
session.createQueue(address, queueName, null, false);
ClientProducer producer = session.createProducer(address);
byte[] bytes = new byte[2000];
ClientMessage message = session.createMessage(false);
message.getBodyBuffer().writeBytes(bytes);
final AtomicBoolean closed = new AtomicBoolean(false);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(500);
closed.set(true);
session.close();
} catch (Exception e) {
}
}
});
t.start();
try {
// This will block
for (int i = 0; i < 10; i++) {
producer.send(message);
}
} catch (ActiveMQObjectClosedException expected) {
}
Assert.assertTrue(closed.get());
t.join();
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class ArtemisBrokerWrapper method translatePolicyMap.
private void translatePolicyMap(Configuration serverConfig, PolicyMap policyMap) {
List allEntries = policyMap.getAllEntries();
Map<String, AddressSettings> settingsMap = serverConfig.getAddressesSettings();
for (Object o : allEntries) {
PolicyEntry entry = (PolicyEntry) o;
org.apache.activemq.command.ActiveMQDestination targetDest = entry.getDestination();
String match = getCorePattern(targetDest);
AddressSettings settings = settingsMap.get(match);
if (settings == null) {
settings = new AddressSettings();
settingsMap.put(match, settings);
}
if (entry.isAdvisoryForSlowConsumers()) {
settings.setSlowConsumerThreshold(1000);
settings.setSlowConsumerCheckPeriod(1);
settings.setSlowConsumerPolicy(SlowConsumerPolicy.NOTIFY);
}
if (entry.isProducerFlowControl()) {
settings.setMaxSizeBytes(10240000).setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
if (bservice.getSystemUsage().isSendFailIfNoSpace()) {
settings.setAddressFullMessagePolicy(AddressFullMessagePolicy.FAIL);
}
}
int queuePrefetch = entry.getQueuePrefetch();
settings.setQueuePrefetch(queuePrefetch);
}
PolicyEntry defaultEntry = policyMap.getDefaultEntry();
if (defaultEntry != null) {
AddressSettings defSettings = settingsMap.get("#");
if (defSettings == null) {
defSettings = new AddressSettings();
settingsMap.put("#", defSettings);
}
if (defaultEntry.isProducerFlowControl()) {
defSettings.setMaxSizeBytes(10240000).setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
if (bservice.getSystemUsage().isSendFailIfNoSpace()) {
defSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.FAIL);
}
}
}
}
Aggregations