use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class MessageConcurrencyTest method testMessageConcurrencyAfterConsumption.
// Test that a created message can be sent via multiple producers after being consumed from a single consumer
@Test
public void testMessageConcurrencyAfterConsumption() throws Exception {
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession consumeSession = sf.createSession();
final ClientProducer mainProducer = consumeSession.createProducer(ADDRESS);
consumeSession.createQueue(ADDRESS, QUEUE_NAME);
ClientConsumer consumer = consumeSession.createConsumer(QUEUE_NAME);
consumeSession.start();
Set<ClientSession> sendSessions = new HashSet<>();
final Set<Sender> senders = new HashSet<>();
final int numSessions = 100;
final int numMessages = 1000;
for (int i = 0; i < numSessions; i++) {
ClientSession sendSession = sf.createSession();
sendSessions.add(sendSession);
ClientProducer producer = sendSession.createProducer(ADDRESS);
Sender sender = new Sender(numMessages, producer);
senders.add(sender);
sender.start();
}
consumer.setMessageHandler(new MessageHandler() {
@Override
public void onMessage(ClientMessage message) {
for (Sender sender : senders) {
sender.queue.add(message);
}
}
});
for (int i = 0; i < numMessages; i++) {
byte[] body = RandomUtil.randomBytes(1000);
ClientMessage message = consumeSession.createMessage(false);
message.getBodyBuffer().writeBytes(body);
mainProducer.send(message);
}
for (Sender sender : senders) {
sender.join();
assertFalse(sender.failed);
}
for (ClientSession sendSession : sendSessions) {
sendSession.close();
}
consumer.close();
consumeSession.deleteQueue(QUEUE_NAME);
consumeSession.close();
sf.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class AckBatchSizeTest method testAckBatchSizeZero.
/*
* tests that when the ackBatchSize is 0 we ack every message directly
* */
@Test
public void testAckBatchSizeZero() throws Exception {
ActiveMQServer server = createServer(false);
server.start();
ServerLocator locator = createInVMNonHALocator().setAckBatchSize(0).setBlockOnAcknowledge(true);
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession sendSession = cf.createSession(false, true, true);
int numMessages = 100;
ClientSession session = cf.createSession(false, true, true);
session.createQueue(addressA, queueA, false);
ClientProducer cp = sendSession.createProducer(addressA);
for (int i = 0; i < numMessages; i++) {
cp.send(sendSession.createMessage(false));
}
ClientConsumer consumer = session.createConsumer(queueA);
session.start();
Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
ClientMessage[] messages = new ClientMessage[numMessages];
for (int i = 0; i < numMessages; i++) {
messages[i] = consumer.receive(5000);
Assert.assertNotNull(messages[i]);
}
for (int i = 0; i < numMessages; i++) {
messages[i].acknowledge();
Assert.assertEquals(numMessages - i - 1, q.getDeliveringCount());
}
sendSession.close();
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class ActiveMQCrashTest method testHang.
@Test
public void testHang() throws Exception {
Configuration configuration = createDefaultInVMConfig().setPersistenceEnabled(false);
server = addServer(ActiveMQServers.newActiveMQServer(configuration));
server.start();
server.getRemotingService().addIncomingInterceptor(new AckInterceptor(server));
// Force an ack at once - this means the send call will block
locator.setConfirmationWindowSize(1);
ClientSessionFactory clientSessionFactory = createSessionFactory(locator);
ClientSession session = clientSessionFactory.createSession();
session.setSendAcknowledgementHandler(new SendAcknowledgementHandler() {
@Override
public void sendAcknowledged(final Message message) {
ackReceived = true;
}
});
ClientProducer producer = session.createProducer("fooQueue");
ClientMessage msg = session.createMessage(false);
msg.putStringProperty("someKey", "someValue");
producer.send(msg);
Thread.sleep(250);
Assert.assertFalse(ackReceived);
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageAvoidLargeMessagesTest method testMixedCompressionSendReceive.
@Test
public void testMixedCompressionSendReceive() throws Exception {
ActiveMQServer server = createServer(true, isNetty());
server.start();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, false, false));
session.createTemporaryQueue(ADDRESS, ADDRESS);
ClientProducer producer = session.createProducer(ADDRESS);
final int minLargeSize = locator.getMinLargeMessageSize();
TestLargeMessageInputStream regularInput = new TestLargeMessageInputStream(minLargeSize);
adjustLargeCompression(true, regularInput, 1024);
TestLargeMessageInputStream largeInput = new TestLargeMessageInputStream(minLargeSize);
largeInput.setSize(100 * minLargeSize);
adjustLargeCompression(false, largeInput, 50 * minLargeSize);
int num = 6;
for (int i = 0; i < num; i++) {
ClientMessage clientFile = session.createMessage(true);
if (i % 2 == 0) {
clientFile.setBodyInputStream(regularInput.clone());
} else {
clientFile.setBodyInputStream(largeInput.clone());
}
producer.send(clientFile);
}
session.commit();
session.start();
// half the messages are sent as large
validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), num / 2);
ClientConsumer consumer = session.createConsumer(ADDRESS);
for (int j = 0; j < num; j++) {
ClientMessage msg1 = consumer.receive(1000);
Assert.assertNotNull(msg1);
if (j % 2 == 0) {
for (int i = 0; i < regularInput.getSize(); i++) {
byte b = msg1.getBodyBuffer().readByte();
Assert.assertEquals("incorrect char ", regularInput.getChar(i), b);
}
} else {
for (int i = 0; i < largeInput.getSize(); i++) {
byte b = msg1.getBodyBuffer().readByte();
Assert.assertEquals("incorrect char ", largeInput.getChar(i), b);
}
}
msg1.acknowledge();
}
session.commit();
consumer.close();
session.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageTest method internalTestResendMessage.
public void internalTestResendMessage(final long messageSize) throws Exception {
clearDataRecreateServerDirs();
ClientSession session = null;
try {
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(false, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
SimpleString ADDRESS2 = ADDRESS.concat("-2");
session.createQueue(ADDRESS2, ADDRESS2, true);
ClientProducer producer = session.createProducer(ADDRESS);
ClientProducer producer2 = session.createProducer(ADDRESS2);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, false);
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientConsumer consumer2 = session.createConsumer(ADDRESS2);
ClientMessage msg1 = consumer.receive(10000);
msg1.acknowledge();
producer2.send(msg1);
session.commit();
ClientMessage msg2 = consumer2.receive(10000);
Assert.assertNotNull(msg2);
msg2.acknowledge();
session.commit();
Assert.assertEquals(messageSize, msg2.getBodySize());
compareString(messageSize, msg2);
session.close();
validateNoFilesOnLargeDir();
} finally {
try {
session.close();
} catch (Throwable ignored) {
}
}
}
Aggregations