use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class ScaleDownTest method testFilters.
@Test
public void testFilters() throws Exception {
final int TEST_SIZE = 50;
final String addressName = "testAddress";
final String evenQueue = "evenQueue";
final String oddQueue = "oddQueue";
createQueue(0, addressName, evenQueue, "0", false);
createQueue(0, addressName, oddQueue, "1", false);
createQueue(1, addressName, evenQueue, "0", false);
createQueue(1, addressName, oddQueue, "1", false);
ClientSessionFactory sf = sfs[0];
ClientSession session = addClientSession(sf.createSession(false, false));
ClientProducer producer = addClientProducer(session.createProducer(addressName));
for (int i = 0; i < TEST_SIZE; i++) {
Message message = session.createMessage(false);
if (i % 2 == 0)
message.putStringProperty(ClusterTestBase.FILTER_PROP, new SimpleString("0"));
else
message.putStringProperty(ClusterTestBase.FILTER_PROP, new SimpleString("1"));
producer.send(message);
}
session.commit();
servers[0].stop();
addConsumer(0, 1, evenQueue, null);
addConsumer(1, 1, oddQueue, null);
for (int i = 0; i < TEST_SIZE; i++) {
String compare;
ClientMessage message;
if (i % 2 == 0) {
message = consumers[0].getConsumer().receive(250);
compare = "0";
} else {
message = consumers[1].getConsumer().receive(250);
compare = "1";
}
Assert.assertEquals(compare, message.getStringProperty(ClusterTestBase.FILTER_PROP));
}
Assert.assertNull(consumers[0].getConsumer().receive(250));
Assert.assertNull(consumers[1].getConsumer().receive(250));
removeConsumer(0);
removeConsumer(1);
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class ServerSessionImpl method send.
@Override
public synchronized RoutingStatus send(Transaction tx, Message msg, final boolean direct, boolean noAutoCreateQueue) throws Exception {
final Message message;
if ((msg.getEncodeSize() > storageManager.getMaxRecordSize()) && !msg.isLargeMessage()) {
message = messageToLargeMessage(msg);
} else {
message = msg;
}
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeSend(this, tx, message, direct, noAutoCreateQueue));
}
// If the protocol doesn't support flow control, we have no choice other than fail the communication
if (!this.getRemotingConnection().isSupportsFlowControl() && pagingManager.isDiskFull()) {
ActiveMQIOErrorException exception = ActiveMQMessageBundle.BUNDLE.diskBeyondLimit();
this.getRemotingConnection().fail(exception);
throw exception;
}
final RoutingStatus result;
// case the id header already generated.
if (!message.isLargeMessage()) {
long id = storageManager.generateID();
// This will re-encode the message
message.setMessageID(id);
}
SimpleString address = message.getAddressSimpleString();
if (defaultAddress == null && address != null) {
defaultAddress = address;
}
if (address == null) {
// We don't want to force a re-encode when the message gets sent to the consumer
message.setAddress(defaultAddress);
}
if (logger.isTraceEnabled()) {
logger.trace("send(message=" + message + ", direct=" + direct + ") being called");
}
if (message.getAddress() == null) {
// This could happen with some tests that are ignoring messages
throw ActiveMQMessageBundle.BUNDLE.noAddress();
}
if (message.getAddressSimpleString().equals(managementAddress)) {
// It's a management message
result = handleManagementMessage(tx, message, direct);
} else {
result = doSend(tx, message, address, direct, noAutoCreateQueue);
}
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterSend(this, tx, message, direct, noAutoCreateQueue, result));
}
return result;
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class PagingTest method testNoCursors.
@Test
public void testNoCursors() throws Exception {
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession();
session.createQueue(ADDRESS, ADDRESS, true);
ClientProducer prod = session.createProducer(ADDRESS);
for (int i = 0; i < 100; i++) {
Message msg = session.createMessage(true);
msg.toCore().getBodyBuffer().writeBytes(new byte[1024]);
prod.send(msg);
}
session.commit();
session.deleteQueue(ADDRESS);
session.close();
sf.close();
locator.close();
server.stop();
server.start();
waitForNotPaging(server.getPagingManager().getPageStore(ADDRESS));
server.stop();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class DeleteMessagesOnStartupTest method testDeleteMessagesOnStartup.
@Test
public void testDeleteMessagesOnStartup() throws Exception {
createStorage();
Queue theQueue = new FakeQueue(new SimpleString(""));
HashMap<Long, Queue> queues = new HashMap<>();
queues.put(100L, theQueue);
Message msg = new CoreMessage(1, 100);
journal.storeMessage(msg);
for (int i = 2; i < 100; i++) {
journal.storeMessage(new CoreMessage(i, 100));
}
journal.storeReference(100, 1, true);
journal.stop();
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
FakePostOffice postOffice = new FakePostOffice();
journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new PostOfficeJournalLoader(postOffice, null, journal, null, null, null, null, null, queues));
Assert.assertEquals(98, deletedMessage.size());
for (Long messageID : deletedMessage) {
Assert.assertTrue("messageID = " + messageID, messageID.longValue() >= 2 && messageID <= 99);
}
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeServerMessageImpl method copy.
@Override
public Message copy() {
SequentialFile newfile = storageManager.createFileForLargeMessage(messageID, durable);
Message newMessage = new LargeServerMessageImpl(this, properties, newfile, messageID);
return newMessage;
}
Aggregations