Java Code Examples for org.apache.activemq.artemis.api.core.client.ClientMessage#saveToOutputStream()
The following examples show how to use
org.apache.activemq.artemis.api.core.client.ClientMessage#saveToOutputStream() .
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: LargeMessageCompressTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testHugeStreamingSpacesCompressed() throws Exception { final long messageSize = 1024L * 1024L; ActiveMQServer server = createServer(true, isNetty()); server.start(); // big enough to hold the whole message compressed on a single message (about 1M on our tests) locator.setMinLargeMessageSize(100 * 1024 * 1024); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = addClientSession(sf.createSession(false, false, false)); session.createQueue(new QueueConfiguration(ADDRESS)); ClientProducer producer = session.createProducer(ADDRESS); ClientMessage clientMessage = session.createMessage(true); clientMessage.setBodyInputStream(new InputStream() { private long count; private boolean closed = false; @Override public void close() throws IOException { super.close(); closed = true; } @Override public int read() throws IOException { if (closed) { throw new IOException("Stream was closed"); } if (count++ < messageSize) { return ' '; } else { return -1; } } }); producer.send(clientMessage); session.commit(); // this is to make sure the message was sent as a regular message (not taking a file on server) validateNoFilesOnLargeDir(); session.start(); ClientConsumer consumer = session.createConsumer(ADDRESS); ClientMessage msg1 = consumer.receive(1000); Assert.assertNotNull(msg1); final AtomicLong numberOfSpaces = new AtomicLong(); msg1.saveToOutputStream(new OutputStream() { @Override public void write(int content) { if (content == ' ') { numberOfSpaces.incrementAndGet(); } } }); assertEquals(messageSize, numberOfSpaces.get()); msg1.acknowledge(); session.commit(); session.close(); }
Example 2
Source File: InterruptedLargeMessageTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testConsumeAfterRestart() throws Exception { ClientSession session = null; LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt(); ActiveMQServer server = createServer(true, isNetty()); server.start(); QueueFactory original = server.getQueueFactory(); locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true); ClientSessionFactory sf = createSessionFactory(locator); session = sf.createSession(false, true, true); session.createQueue(new QueueConfiguration(ADDRESS)); ClientProducer producer = session.createProducer(ADDRESS); for (int i = 0; i < 10; i++) { Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true); producer.send(clientFile); } session.commit(); session.close(); sf.close(); server.stop(); server.start(); sf = createSessionFactory(locator); session = sf.createSession(false, false); ClientConsumer cons = session.createConsumer(ADDRESS); session.start(); for (int i = 0; i < 10; i++) { ClientMessage msg = cons.receive(5000); Assert.assertNotNull(msg); msg.saveToOutputStream(new java.io.OutputStream() { @Override public void write(int b) throws IOException { } }); msg.acknowledge(); session.commit(); } ((ActiveMQServerImpl) server).replaceQueueFactory(original); server.fail(false); server.start(); server.stop(); validateNoFilesOnLargeDir(); }
Example 3
Source File: LargeMessageCompressTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testLargeMessageCompression3() throws Exception { final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE); ActiveMQServer server = createServer(true, isNetty()); server.start(); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = addClientSession(sf.createSession(false, false, false)); session.createQueue(new QueueConfiguration(ADDRESS).setAddress(ADDRESS).setDurable(false).setTemporary(true)); ClientProducer producer = session.createProducer(ADDRESS); Message clientFile = createLargeClientMessageStreaming(session, messageSize, true); producer.send(clientFile); session.commit(); session.start(); ClientConsumer consumer = session.createConsumer(ADDRESS); ClientMessage msg1 = consumer.receive(1000); Assert.assertNotNull(msg1); String testDir = getTestDir(); File testFile = new File(testDir, "async_large_message"); FileOutputStream output = new FileOutputStream(testFile); msg1.saveToOutputStream(output); msg1.acknowledge(); output.close(); session.commit(); consumer.close(); session.close(); //verify FileInputStream input = new FileInputStream(testFile); for (int i = 0; i < messageSize; i++) { byte b = (byte) input.read(); assertEquals("position = " + i, getSamplebyte(i), b); } input.close(); testFile.delete(); validateNoFilesOnLargeDir(); }
Example 4
Source File: LargeMessageCompressTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testLargeMessageCompressionRestartAndCheckSize() throws Exception { final int messageSize = 1024 * 1024; ActiveMQServer server = createServer(true, isNetty()); server.start(); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = addClientSession(sf.createSession(false, false, false)); session.createQueue(new QueueConfiguration(ADDRESS)); ClientProducer producer = session.createProducer(ADDRESS); byte[] msgs = new byte[1024 * 1024]; for (int i = 0; i < msgs.length; i++) { msgs[i] = RandomUtil.randomByte(); } Message clientFile = createLargeClientMessage(session, msgs, true); producer.send(clientFile); session.commit(); session.close(); sf.close(); locator.close(); server.stop(); server = createServer(true, isNetty()); server.start(); locator = createFactory(isNetty()); sf = createSessionFactory(locator); session = sf.createSession(); session.start(); ClientConsumer consumer = session.createConsumer(ADDRESS); ClientMessage msg1 = consumer.receive(1000); Assert.assertNotNull(msg1); assertEquals(messageSize, msg1.getBodySize()); String testDir = getTestDir(); File testFile = new File(testDir, "async_large_message"); FileOutputStream output = new FileOutputStream(testFile); msg1.saveToOutputStream(output); msg1.acknowledge(); session.commit(); consumer.close(); session.close(); //verify FileInputStream input = new FileInputStream(testFile); for (int i = 0; i < messageSize; i++) { byte b = (byte) input.read(); assertEquals("position = " + i, msgs[i], b); } input.close(); testFile.delete(); validateNoFilesOnLargeDir(); }