use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class OpenWireLargeMessageTest method testSendReceiveLargeMessage.
@Test
public void testSendReceiveLargeMessage() throws Exception {
// Create 1MB Message
int size = 1024 * 1024;
byte[] bytes = new byte[size];
try (Connection connection = factory.createConnection()) {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(lmAddress.toString());
MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
bytes[0] = 1;
BytesMessage message = session.createBytesMessage();
message.writeBytes(bytes);
producer.send(message);
}
server.stop();
server.start();
try (Connection connection = factory.createConnection()) {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(lmAddress.toString());
MessageConsumer consumer = session.createConsumer(queue);
BytesMessage m = (BytesMessage) consumer.receive();
assertNotNull(m);
byte[] body = new byte[size];
m.readBytes(body);
assertArrayEquals(body, bytes);
}
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class SimpleOpenWireTest method testSendEmptyMessages.
@Test
public void testSendEmptyMessages() throws Exception {
Queue dest = new ActiveMQQueue(queueName);
QueueSession defaultQueueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender defaultSender = defaultQueueSession.createSender(dest);
defaultSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
connection.start();
Message msg = defaultQueueSession.createMessage();
msg.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(msg);
QueueReceiver queueReceiver = defaultQueueSession.createReceiver(dest);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// bytes
BytesMessage bytesMessage = defaultQueueSession.createBytesMessage();
bytesMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(bytesMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// map
MapMessage mapMessage = defaultQueueSession.createMapMessage();
mapMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(mapMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// object
ObjectMessage objMessage = defaultQueueSession.createObjectMessage();
objMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(objMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// stream
StreamMessage streamMessage = defaultQueueSession.createStreamMessage();
streamMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(streamMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
// text
TextMessage textMessage = defaultQueueSession.createTextMessage();
textMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(textMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class JMSMessageTest method testBytesMessageLength.
@Test
public void testBytesMessageLength() throws Exception {
// Receive a message with the JMS API
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
MessageProducer producer = session.createProducer(destination);
// Send the message
{
BytesMessage message = session.createBytesMessage();
message.writeInt(1);
message.writeInt(2);
message.writeInt(3);
message.writeInt(4);
producer.send(message);
}
// Check the message.
{
BytesMessage message = (BytesMessage) consumer.receive(1000);
assertNotNull(message);
assertEquals(16, message.getBodyLength());
}
assertNull(consumer.receiveNoWait());
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class JMSMessageTest method testBytesMessage.
@Test
public void testBytesMessage() throws Exception {
// Receive a message with the JMS API
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
MessageProducer producer = session.createProducer(destination);
// Send the message
{
BytesMessage message = session.createBytesMessage();
message.writeBoolean(true);
producer.send(message);
}
// Check the message
{
BytesMessage message = (BytesMessage) consumer.receive(1000);
assertNotNull(message);
assertTrue(message.readBoolean());
try {
message.readByte();
fail("Expected exception not thrown.");
} catch (MessageEOFException e) {
}
}
assertNull(consumer.receiveNoWait());
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class PerfProducer method run.
@Override
public void run() {
try {
while (isRunning()) {
BytesMessage msg;
msg = session.createBytesMessage();
msg.writeBytes(payload);
producer.send(msg);
if (this.transacted) {
this.session.commit();
}
rate.increment();
if (sleep > 0) {
Thread.sleep(sleep);
}
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
stopped.countDown();
}
}
Aggregations