Search in sources :

Example 11 with ClientMessageImpl

use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.

the class MessageBufferTest method simpleTest.

@Test
public void simpleTest() throws Exception {
    final String data = "Simple Text " + UUID.randomUUID().toString();
    final String queueName = "simpleQueue";
    final String addressName = "simpleAddress";
    session.createQueue(addressName, RoutingType.ANYCAST, queueName);
    ClientProducer producer = session.createProducer(addressName);
    ClientMessageImpl message = (ClientMessageImpl) session.createMessage(true);
    message.getBodyBuffer().writeString(data);
    for (int i = 0; i < 100; i++) {
        message.putStringProperty("key", "int" + i);
        // JMS layer will always call this before sending
        message.getBodyBuffer().resetReaderIndex();
        producer.send(message);
        session.commit();
        Assert.assertTrue("Message body growing indefinitely and unexpectedly", message.getBodySize() < 1000);
    }
    producer.send(message);
    producer.close();
    ClientConsumer consumer = session.createConsumer(queueName);
    session.start();
    assertNotNull(message);
    message.acknowledge();
    assertEquals(data, message.getBodyBuffer().readString());
}
Also used : ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) Test(org.junit.Test)

Example 12 with ClientMessageImpl

use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.

the class MessageImplTest method getSetAttributes.

@Test
public void getSetAttributes() {
    for (int j = 0; j < 10; j++) {
        byte[] bytes = new byte[1000];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = RandomUtil.randomByte();
        }
        final byte type = RandomUtil.randomByte();
        final boolean durable = RandomUtil.randomBoolean();
        final long expiration = RandomUtil.randomLong();
        final long timestamp = RandomUtil.randomLong();
        final byte priority = RandomUtil.randomByte();
        ICoreMessage message1 = new ClientMessageImpl(type, durable, expiration, timestamp, priority, 100);
        ICoreMessage message = message1;
        Assert.assertEquals(type, message.getType());
        Assert.assertEquals(durable, message.isDurable());
        Assert.assertEquals(expiration, message.getExpiration());
        Assert.assertEquals(timestamp, message.getTimestamp());
        Assert.assertEquals(priority, message.getPriority());
        final SimpleString destination = new SimpleString(RandomUtil.randomString());
        final boolean durable2 = RandomUtil.randomBoolean();
        final long expiration2 = RandomUtil.randomLong();
        final long timestamp2 = RandomUtil.randomLong();
        final byte priority2 = RandomUtil.randomByte();
        message.setAddress(destination);
        Assert.assertEquals(destination, message.getAddressSimpleString());
        message.setDurable(durable2);
        Assert.assertEquals(durable2, message.isDurable());
        message.setExpiration(expiration2);
        Assert.assertEquals(expiration2, message.getExpiration());
        message.setTimestamp(timestamp2);
        Assert.assertEquals(timestamp2, message.getTimestamp());
        message.setPriority(priority2);
        Assert.assertEquals(priority2, message.getPriority());
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) Test(org.junit.Test)

Example 13 with ClientMessageImpl

use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.

the class CoreMessageTest method generate.

public String generate(String body) throws Exception {
    ClientMessageImpl message = new ClientMessageImpl(MESSAGE_TYPE, DURABLE, EXPIRATION, TIMESTAMP, PRIORITY, 10 * 1024, null);
    TextMessageUtil.writeBodyText(message.getBodyBuffer(), SimpleString.toSimpleString(body));
    message.setAddress(ADDRESS);
    message.setUserID(uuid);
    message.getProperties().putSimpleStringProperty(PROP1_NAME, PROP1_VALUE);
    ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(10 * 1024);
    message.sendBuffer(buffer.byteBuf(), 0);
    byte[] bytes = new byte[buffer.byteBuf().writerIndex()];
    buffer.byteBuf().readBytes(bytes);
    return encodeString(bytes);
// replace the code
}
Also used : ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 14 with ClientMessageImpl

use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.

the class MessageHeaderTest method testCopyOnForeignMapMessage.

@Test
public void testCopyOnForeignMapMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    MapMessage foreignMapMessage = new SimpleJMSMapMessage();
    foreignMapMessage.setInt("int", 1);
    foreignMapMessage.setString("string", "test");
    ActiveMQMapMessage copy = new ActiveMQMapMessage(foreignMapMessage, session);
    MessageHeaderTestBase.ensureEquivalent(foreignMapMessage, copy);
}
Also used : ActiveMQMapMessage(org.apache.activemq.artemis.jms.client.ActiveMQMapMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) MapMessage(javax.jms.MapMessage) ActiveMQMapMessage(org.apache.activemq.artemis.jms.client.ActiveMQMapMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) Test(org.junit.Test)

Example 15 with ClientMessageImpl

use of org.apache.activemq.artemis.core.client.impl.ClientMessageImpl in project activemq-artemis by apache.

the class MessageHeaderTest method testCopyOnForeignMessage.

@Test
public void testCopyOnForeignMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    Message foreignMessage = new SimpleJMSMessage();
    ActiveMQMessage copy = new ActiveMQMessage(foreignMessage, session);
    MessageHeaderTestBase.ensureEquivalent(foreignMessage, copy);
}
Also used : MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) ActiveMQObjectMessage(org.apache.activemq.artemis.jms.client.ActiveMQObjectMessage) BytesMessage(javax.jms.BytesMessage) ActiveMQBytesMessage(org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage) ActiveMQMapMessage(org.apache.activemq.artemis.jms.client.ActiveMQMapMessage) ActiveMQStreamMessage(org.apache.activemq.artemis.jms.client.ActiveMQStreamMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage) Test(org.junit.Test)

Aggregations

ClientMessageImpl (org.apache.activemq.artemis.core.client.impl.ClientMessageImpl)17 Test (org.junit.Test)16 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)8 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)8 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BytesMessage (javax.jms.BytesMessage)2 MapMessage (javax.jms.MapMessage)2 ObjectMessage (javax.jms.ObjectMessage)2 StreamMessage (javax.jms.StreamMessage)2 TextMessage (javax.jms.TextMessage)2 Message (org.apache.activemq.artemis.api.core.Message)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)2 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)2 SessionSendMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage)2 ActiveMQBytesMessage (org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage)2 ActiveMQMapMessage (org.apache.activemq.artemis.jms.client.ActiveMQMapMessage)2