org.apache.activemq.command.ActiveMQBytesMessage

Here are the examples of the java api class org.apache.activemq.command.ActiveMQBytesMessage taken from open source projects.

1. MessageCompressionTest#testBytesMessageCompressionActiveMQ()

View license
@Test
public void testBytesMessageCompressionActiveMQ() throws Exception {
    sendAMQBytesMessage(TEXT);
    ActiveMQBytesMessage message = receiveAMQBytesMessage();
    int compressedSize = message.getContent().getLength();
    byte[] bytes = new byte[TEXT.getBytes("UTF8").length];
    message.readBytes(bytes);
    assertTrue(message.readBytes(new byte[255]) == -1);
    String rcvString = new String(bytes, "UTF8");
    assertEquals(TEXT, rcvString);
    assertTrue(message.isCompressed());
    sendAMQBytesMessage(TEXT, false);
    message = receiveAMQBytesMessage();
    int unCompressedSize = message.getContent().getLength();
    assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize);
}

2. OpenTypeSupportTest#testBrowseByteMessageFails()

View license
@Test
public void testBrowseByteMessageFails() throws Exception {
    ActiveMQBytesMessage bm = new ActiveMQBytesMessage();
    bm.writeBytes("123456".getBytes());
    Object result = OpenTypeSupport.convert(bm);
    LOG.info("result : " + result);
}

3. CompressionOverNetworkTest#testBytesMessageCompression()

View license
@Test
public void testBytesMessageCompression() throws Exception {
    MessageConsumer consumer1 = remoteSession.createConsumer(included);
    MessageProducer producer = localSession.createProducer(included);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    waitForConsumerRegistration(localBroker, 1, included);
    StringBuilder payload = new StringBuilder("test-");
    for (int i = 0; i < 100; ++i) {
        payload.append(UUID.randomUUID().toString());
    }
    byte[] bytes = payload.toString().getBytes(StandardCharsets.UTF_8);
    BytesMessage test = localSession.createBytesMessage();
    test.writeBytes(bytes);
    producer.send(test);
    Message msg = consumer1.receive(RECEIVE_TIMEOUT_MILLS);
    assertNotNull(msg);
    ActiveMQBytesMessage message = (ActiveMQBytesMessage) msg;
    assertTrue(message.isCompressed());
    assertTrue(message.getContent().getLength() < bytes.length);
    byte[] result = new byte[bytes.length];
    assertEquals(bytes.length, message.readBytes(result));
    assertEquals(-1, message.readBytes(result));
    for (int i = 0; i < bytes.length; ++i) {
        assertEquals(bytes[i], result[i]);
    }
}

4. ActiveMQBytesMessageTest#createObject()

View license
@Override
public Object createObject() throws Exception {
    ActiveMQBytesMessage info = new ActiveMQBytesMessage();
    populateObject(info);
    return info;
}

5. ActiveMQBytesMessageTest#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ActiveMQBytesMessage info = (ActiveMQBytesMessage) object;
}

6. ActiveMQBytesMessageTest#createObject()

View license
@Override
public Object createObject() throws Exception {
    ActiveMQBytesMessage info = new ActiveMQBytesMessage();
    populateObject(info);
    return info;
}

7. ActiveMQBytesMessageTest#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ActiveMQBytesMessage info = (ActiveMQBytesMessage) object;
}

8. MessageCompressionTest#receiveAMQBytesMessage()

View license
private ActiveMQBytesMessage receiveAMQBytesMessage() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionURI);
    ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(getActiveMQQueue());
    ActiveMQBytesMessage rc = (ActiveMQBytesMessage) consumer.receive();
    connection.close();
    return rc;
}