Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientMessage#getBodyBuffer()
The following examples show how to use
org.apache.activemq.artemis.api.core.client.ClientMessage#getBodyBuffer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalPagingTest.java From activemq-artemis with Apache License 2.0 | 7 votes |
protected void sendFewMessages(int numberOfMessages, ClientSession session, ClientProducer producer, byte[] body) throws ActiveMQException { ClientMessage message; for (int i = 0; i < numberOfMessages; i++) { message = session.createMessage(true); ActiveMQBuffer bodyLocal = message.getBodyBuffer(); bodyLocal.writeBytes(body); producer.send(message); if (i % 1000 == 0) { session.commit(); } } session.commit(); }
Example 2
Source File: FailoverTestBase.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Large message version of {@link #assertMessageBody(int, ClientMessage)}. * * @param i * @param message */ protected static void assertLargeMessageBody(final int i, final ClientMessage message) { ActiveMQBuffer buffer = message.getBodyBuffer(); for (int j = 0; j < LARGE_MESSAGE_SIZE; j++) { Assert.assertTrue("msg " + i + ", expecting " + LARGE_MESSAGE_SIZE + " bytes, got " + j, buffer.readable()); Assert.assertEquals("equal at " + j, ActiveMQTestBase.getSamplebyte(j), buffer.readByte()); } }
Example 3
Source File: FailoverWithDivertTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private ClientMessage createLargeMessage(ClientSession session, final int largeSize) { ClientMessage message = session.createMessage(true); ActiveMQBuffer bodyBuffer = message.getBodyBuffer(); final int propSize = 10240; while (bodyBuffer.writerIndex() < largeSize) { byte[] prop = new byte[propSize]; bodyBuffer.writeBytes(prop); } return message; }
Example 4
Source File: LargeMessageReplicationTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private ClientMessage createLargeMessage(ClientSession session, final int largeSize) { ClientMessage message = session.createMessage(true); ActiveMQBuffer bodyBuffer = message.getBodyBuffer(); final int propSize = 10240; while (bodyBuffer.writerIndex() < largeSize) { byte[] prop = new byte[propSize]; bodyBuffer.writeBytes(prop); } return message; }
Example 5
Source File: QueueControlTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testRemoveAllWithPagingMode() throws Exception { final int MESSAGE_SIZE = 1024 * 3; // 3k // reset maxSize for Paging mode Field maxSizField = PagingManagerImpl.class.getDeclaredField("maxSize"); maxSizField.setAccessible(true); maxSizField.setLong(server.getPagingManager(), 10240); clearDataRecreateServerDirs(); SimpleString address = RandomUtil.randomSimpleString(); SimpleString queueName = RandomUtil.randomSimpleString(); session.createQueue(new QueueConfiguration(queueName).setAddress(address).setDurable(durable)); Queue queue = server.locateQueue(queueName); Assert.assertFalse(queue.getPageSubscription().isPaging()); ClientProducer producer = session.createProducer(address); byte[] body = new byte[MESSAGE_SIZE]; ByteBuffer bb = ByteBuffer.wrap(body); for (int j = 1; j <= MESSAGE_SIZE; j++) { bb.put(getSamplebyte(j)); } final int numberOfMessages = 8000; ClientMessage message; for (int i = 0; i < numberOfMessages; i++) { message = session.createMessage(true); ActiveMQBuffer bodyLocal = message.getBodyBuffer(); bodyLocal.writeBytes(body); producer.send(message); } Assert.assertTrue(queue.getPageSubscription().isPaging()); QueueControl queueControl = createManagementControl(address, queueName); assertMessageMetrics(queueControl, numberOfMessages, durable); int removedMatchedMessagesCount = queueControl.removeAllMessages(); Assert.assertEquals(numberOfMessages, removedMatchedMessagesCount); assertMessageMetrics(queueControl, 0, durable); Field queueMemoprySizeField = QueueImpl.class.getDeclaredField("queueMemorySize"); queueMemoprySizeField.setAccessible(true); AtomicInteger queueMemorySize = (AtomicInteger) queueMemoprySizeField.get(queue); Assert.assertEquals(0, queueMemorySize.get()); session.deleteQueue(queueName); }
Example 6
Source File: BackupSyncLargeMessageTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * LargeMessages are passed from the client to the server in chunks. Here we test the backup * starting the data synchronization with the live in the middle of a multiple chunks large * message upload from the client to the live server. * * @throws Exception */ @Test public void testBackupStartsWhenLiveIsReceivingLargeMessage() throws Exception { final ClientSession session = addClientSession(sessionFactory.createSession(true, true)); session.createQueue(new QueueConfiguration(FailoverTestBase.ADDRESS)); final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS); final ClientMessage message = session.createMessage(true); final int largeMessageSize = 1000 * MIN_LARGE_MESSAGE; message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(largeMessageSize)); final AtomicBoolean caughtException = new AtomicBoolean(false); final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); Runnable r = new Runnable() { @Override public void run() { try { latch.countDown(); producer.send(message); sendMessages(session, producer, 20); session.commit(); } catch (ActiveMQException e) { e.printStackTrace(); caughtException.set(true); } finally { latch2.countDown(); } } }; Executors.defaultThreadFactory().newThread(r).start(); waitForLatch(latch); startBackupFinishSyncing(); ActiveMQTestBase.waitForLatch(latch2); crash(session); assertFalse("no exceptions while sending message", caughtException.get()); session.start(); ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS); ClientMessage msg = consumer.receive(2000); ActiveMQBuffer buffer = msg.getBodyBuffer(); for (int j = 0; j < largeMessageSize; j++) { Assert.assertTrue("large msg , expecting " + largeMessageSize + " bytes, got " + j, buffer.readable()); Assert.assertEquals("equal at " + j, ActiveMQTestBase.getSamplebyte(j), buffer.readByte()); } receiveMessages(consumer, 0, 20, true); assertNull("there should be no more messages!", consumer.receiveImmediate()); consumer.close(); session.commit(); }
Example 7
Source File: SelfExpandingBufferTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
private void testSelfExpandingBuffer(final boolean netty, final boolean persistent) throws Exception { setUpService(netty, persistent); ClientSessionFactory factory; ServerLocator locator = createFactory(netty); factory = createSessionFactory(locator); ClientSession session = factory.createSession(false, true, true); try { session.createQueue(new QueueConfiguration(ADDRESS)); ClientMessage msg = session.createMessage(true); ActiveMQBuffer buffer = msg.getBodyBuffer(); byte[] bytes = RandomUtil.randomBytes(10 * buffer.capacity()); buffer.writeBytes(bytes); ClientProducer prod = session.createProducer(ADDRESS); prod.send(msg); // Send same message again prod.send(msg); ClientConsumer cons = session.createConsumer(ADDRESS); session.start(); ClientMessage msg2 = cons.receive(3000); Assert.assertNotNull(msg2); byte[] receivedBytes = new byte[bytes.length]; // log.debug("buffer start pos should be at " + PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT); // // log.debug("buffer pos at " + msg2.getBodyBuffer().readerIndex()); // // log.debug("buffer length should be " + msg2.getBodyBuffer().readInt(PacketImpl.PACKET_HEADERS_SIZE)); msg2.getBodyBuffer().readBytes(receivedBytes); ActiveMQTestBase.assertEqualsByteArrays(bytes, receivedBytes); msg2 = cons.receive(3000); Assert.assertNotNull(msg2); msg2.getBodyBuffer().readBytes(receivedBytes); ActiveMQTestBase.assertEqualsByteArrays(bytes, receivedBytes); } finally { session.close(); } }
Example 8
Source File: CoreClientTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
private void testCoreClient(final boolean netty, ServerLocator serverLocator) throws Exception { final SimpleString QUEUE = new SimpleString("CoreClientTestQueue"); ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultConfig(netty), false)); server.start(); ServerLocator locator = serverLocator == null ? createNonHALocator(netty) : serverLocator; ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, true, true); session.createQueue(new QueueConfiguration(QUEUE).setDurable(false)); ClientProducer producer = session.createProducer(QUEUE); final int numMessages = 1000; for (int i = 0; i < numMessages; i++) { ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1); message.putStringProperty("foo", "bar"); // One way around the setting destination problem is as follows - // Remove destination as an attribute from client producer. // The destination always has to be set explicitly before sending a message message.setAddress(QUEUE); message.getBodyBuffer().writeString("testINVMCoreClient"); producer.send(message); } ClientConsumer consumer = session.createConsumer(QUEUE); session.start(); for (int i = 0; i < numMessages; i++) { ClientMessage message2 = consumer.receive(); ActiveMQBuffer buffer = message2.getBodyBuffer(); Assert.assertEquals("testINVMCoreClient", buffer.readString()); message2.acknowledge(); } sf.close(); }
Example 9
Source File: LargeMessageTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
private void fillAddress() throws Exception { final int PAGE_MAX = 100 * 1024; final int PAGE_SIZE = 10 * 1024; final int MESSAGE_SIZE = 1024; // 1k Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false); ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>(), storeType); server.start(); server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.DROP); locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, false, false); session.createQueue(new QueueConfiguration(ADDRESS)); ClientProducer producer = session.createProducer(ADDRESS); ClientMessage message; byte[] body = new byte[MESSAGE_SIZE]; ByteBuffer bb = ByteBuffer.wrap(body); for (int j = 1; j <= MESSAGE_SIZE; j++) { bb.put(getSamplebyte(j)); } for (int i = 0; i < 5000; i++) { message = session.createMessage(true); ActiveMQBuffer bodyLocal = message.getBodyBuffer(); bodyLocal.writeBytes(body); message.putIntProperty(new SimpleString("id"), i); producer.send(message); if (i % 1000 == 0) { session.commit(); } } session.commit(); session.close(); }
Example 10
Source File: PagingSyncTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testOrder1() throws Throwable { boolean persistentMessages = true; Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false); ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>()); server.start(); final int messageSize = 1024; final int numberOfMessages = 500; ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).setBlockOnAcknowledge(false).setConsumerWindowSize(1024 * 1024); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(false, false, false); server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST)); server.createQueue(new QueueConfiguration(ADDRESS).setRoutingType(RoutingType.ANYCAST)); ClientProducer producer = session.createProducer(PagingTest.ADDRESS); byte[] body = new byte[messageSize]; ByteBuffer bb = ByteBuffer.wrap(body); for (int j = 1; j <= messageSize; j++) { bb.put(getSamplebyte(j)); } for (int i = 0; i < numberOfMessages; i++) { ClientMessage message = session.createMessage(persistentMessages); ActiveMQBuffer bodyLocal = message.getBodyBuffer(); bodyLocal.writeBytes(body); message.putIntProperty(new SimpleString("id"), i); producer.send(message); } session.commit(); session.close(); }