Search in sources :

Example 56 with BytesMessage

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);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 57 with BytesMessage

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));
}
Also used : MapMessage(javax.jms.MapMessage) StreamMessage(javax.jms.StreamMessage) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) ObjectMessage(javax.jms.ObjectMessage) MapMessage(javax.jms.MapMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) BytesMessage(javax.jms.BytesMessage) StreamMessage(javax.jms.StreamMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 58 with BytesMessage

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());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 59 with BytesMessage

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());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageEOFException(javax.jms.MessageEOFException) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 60 with BytesMessage

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();
    }
}
Also used : BytesMessage(javax.jms.BytesMessage)

Aggregations

BytesMessage (javax.jms.BytesMessage)180 Session (javax.jms.Session)79 MessageProducer (javax.jms.MessageProducer)77 MessageConsumer (javax.jms.MessageConsumer)70 Test (org.junit.Test)59 Message (javax.jms.Message)54 TextMessage (javax.jms.TextMessage)47 Connection (javax.jms.Connection)41 Queue (javax.jms.Queue)37 JMSException (javax.jms.JMSException)34 MapMessage (javax.jms.MapMessage)29 ObjectMessage (javax.jms.ObjectMessage)26 StreamMessage (javax.jms.StreamMessage)20 HashMap (java.util.HashMap)18 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 Topic (javax.jms.Topic)14 Map (java.util.Map)12 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)12 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)10 Destination (javax.jms.Destination)9