Search in sources :

Example 36 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.

the class CompressionOverNetworkTest method testTextMessageCompression.

@Test
public void testTextMessageCompression() 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());
    }
    Message test = localSession.createTextMessage(payload.toString());
    producer.send(test);
    Message msg = consumer1.receive(RECEIVE_TIMEOUT_MILLS);
    assertNotNull(msg);
    ActiveMQTextMessage message = (ActiveMQTextMessage) msg;
    assertTrue(message.isCompressed());
    assertEquals(payload.toString(), message.getText());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQBytesMessage(org.apache.activemq.command.ActiveMQBytesMessage) MapMessage(javax.jms.MapMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ActiveMQObjectMessage(org.apache.activemq.command.ActiveMQObjectMessage) Message(javax.jms.Message) ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) StreamMessage(javax.jms.StreamMessage) BytesMessage(javax.jms.BytesMessage) ActiveMQStreamMessage(org.apache.activemq.command.ActiveMQStreamMessage) MessageProducer(javax.jms.MessageProducer) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 37 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.

the class DataFileGeneratorTestSupport method createMessage.

protected Message createMessage(String string) throws Exception {
    ActiveMQTextMessage message = (ActiveMQTextMessage) ActiveMQTextMessageTest.SINGLETON.createObject();
    message.setText(string);
    return message;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 38 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.

the class NumberRangesWhileMarshallingTest method testMaxFrameSize.

public void testMaxFrameSize() throws Exception {
    OpenWireFormat wf = new OpenWireFormat();
    wf.setMaxFrameSize(10);
    ActiveMQTextMessage msg = new ActiveMQTextMessage();
    msg.setText("This is a test");
    writeObject(msg);
    ds.writeInt(endOfStreamMarker);
    // now lets read from the stream
    ds.close();
    ByteArrayInputStream in = new ByteArrayInputStream(buffer.toByteArray());
    DataInputStream dis = new DataInputStream(in);
    try {
        wf.unmarshal(dis);
    } catch (IOException ioe) {
        return;
    }
    fail("Should fail because of the large frame size");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 39 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.

the class RedeliveryPolicyTest method testRepeatedRedeliveryOnMessageNoCommit.

public void testRepeatedRedeliveryOnMessageNoCommit() throws Exception {
    connection.start();
    Session dlqSession = connection.createSession(true, Session.SESSION_TRANSACTED);
    ActiveMQQueue destination = new ActiveMQQueue("TEST");
    MessageProducer producer = dlqSession.createProducer(destination);
    // Send the messages
    producer.send(dlqSession.createTextMessage("1st"));
    dlqSession.commit();
    MessageConsumer dlqConsumer = dlqSession.createConsumer(new ActiveMQQueue("ActiveMQ.DLQ"));
    final int maxRedeliveries = 4;
    final AtomicInteger receivedCount = new AtomicInteger(0);
    for (int i = 0; i <= maxRedeliveries + 1; i++) {
        connection = (ActiveMQConnection) factory.createConnection(userName, password);
        connections.add(connection);
        RedeliveryPolicy policy = connection.getRedeliveryPolicy();
        policy.setInitialRedeliveryDelay(0);
        policy.setUseExponentialBackOff(false);
        policy.setMaximumRedeliveries(maxRedeliveries);
        connection.start();
        final Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        MessageConsumer consumer = session.createConsumer(destination);
        final CountDownLatch done = new CountDownLatch(1);
        consumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(Message message) {
                try {
                    ActiveMQTextMessage m = (ActiveMQTextMessage) message;
                    assertEquals("1st", m.getText());
                    assertEquals(receivedCount.get(), m.getRedeliveryCounter());
                    receivedCount.incrementAndGet();
                    done.countDown();
                } catch (Exception ignored) {
                    ignored.printStackTrace();
                }
            }
        });
        if (i <= maxRedeliveries) {
            assertTrue("listener done", done.await(5, TimeUnit.SECONDS));
        } else {
            // final redlivery gets poisoned before dispatch
            assertFalse("listener done", done.await(1, TimeUnit.SECONDS));
        }
        connection.close();
        connections.remove(connection);
    }
    // We should be able to get the message off the DLQ now.
    TextMessage m = (TextMessage) dlqConsumer.receive(1000);
    assertNotNull("Got message from DLQ", m);
    assertEquals("1st", m.getText());
    String cause = m.getStringProperty(ActiveMQMessage.DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
    assertTrue("cause exception has policy ref", cause.contains("RedeliveryPolicy"));
    dlqSession.commit();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) JMSException(javax.jms.JMSException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Session(javax.jms.Session) ServerSession(javax.jms.ServerSession)

Example 40 with ActiveMQTextMessage

use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.

the class RedeliveryPolicyTest method testRepeatedRedeliveryServerSessionNoCommit.

public void testRepeatedRedeliveryServerSessionNoCommit() throws Exception {
    connection.start();
    Session dlqSession = connection.createSession(true, Session.SESSION_TRANSACTED);
    ActiveMQQueue destination = new ActiveMQQueue("TEST");
    MessageProducer producer = dlqSession.createProducer(destination);
    // Send the messages
    producer.send(dlqSession.createTextMessage("1st"));
    dlqSession.commit();
    MessageConsumer dlqConsumer = dlqSession.createConsumer(new ActiveMQQueue("ActiveMQ.DLQ"));
    final int maxRedeliveries = 4;
    final AtomicInteger receivedCount = new AtomicInteger(0);
    for (int i = 0; i <= maxRedeliveries + 1; i++) {
        connection = (ActiveMQConnection) factory.createConnection(userName, password);
        connections.add(connection);
        RedeliveryPolicy policy = connection.getRedeliveryPolicy();
        policy.setInitialRedeliveryDelay(0);
        policy.setUseExponentialBackOff(false);
        policy.setMaximumRedeliveries(maxRedeliveries);
        connection.start();
        final CountDownLatch done = new CountDownLatch(1);
        final ActiveMQSession session = (ActiveMQSession) connection.createSession(true, Session.SESSION_TRANSACTED);
        session.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(Message message) {
                try {
                    ActiveMQTextMessage m = (ActiveMQTextMessage) message;
                    assertEquals("1st", m.getText());
                    assertEquals(receivedCount.get(), m.getRedeliveryCounter());
                    receivedCount.incrementAndGet();
                    done.countDown();
                } catch (Exception ignored) {
                    ignored.printStackTrace();
                }
            }
        });
        connection.createConnectionConsumer(destination, null, new ServerSessionPool() {

            @Override
            public ServerSession getServerSession() throws JMSException {
                return new ServerSession() {

                    @Override
                    public Session getSession() throws JMSException {
                        return session;
                    }

                    @Override
                    public void start() throws JMSException {
                    }
                };
            }
        }, 100, false);
        Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                session.run();
                return done.await(10, TimeUnit.MILLISECONDS);
            }
        });
        if (i <= maxRedeliveries) {
            assertTrue("listener done @" + i, done.await(5, TimeUnit.SECONDS));
        } else {
            // final redlivery gets poisoned before dispatch
            assertFalse("listener not done @" + i, done.await(1, TimeUnit.SECONDS));
        }
        connection.close();
        connections.remove(connection);
    }
    // We should be able to get the message off the DLQ now.
    TextMessage m = (TextMessage) dlqConsumer.receive(1000);
    assertNotNull("Got message from DLQ", m);
    assertEquals("1st", m.getText());
    String cause = m.getStringProperty(ActiveMQMessage.DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
    assertTrue("cause exception has policy ref", cause.contains("RedeliveryPolicy"));
    dlqSession.commit();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ServerSessionPool(javax.jms.ServerSessionPool) ServerSession(javax.jms.ServerSession) TextMessage(javax.jms.TextMessage) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) JMSException(javax.jms.JMSException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) Wait(org.apache.activemq.util.Wait) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Session(javax.jms.Session) ServerSession(javax.jms.ServerSession)

Aggregations

ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)71 Test (org.junit.Test)36 TextMessage (javax.jms.TextMessage)16 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)14 Message (javax.jms.Message)10 MessageProducer (javax.jms.MessageProducer)10 MessageConsumer (javax.jms.MessageConsumer)9 MessageId (org.apache.activemq.command.MessageId)9 JMSException (javax.jms.JMSException)7 ActiveMQBytesMessage (org.apache.activemq.command.ActiveMQBytesMessage)7 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)6 MessageReference (org.apache.activemq.broker.region.MessageReference)6 Queue (org.apache.activemq.broker.region.Queue)6 ActiveMQMapMessage (org.apache.activemq.command.ActiveMQMapMessage)6 ActiveMQObjectMessage (org.apache.activemq.command.ActiveMQObjectMessage)6 ActiveMQStreamMessage (org.apache.activemq.command.ActiveMQStreamMessage)6 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)6 SystemUsage (org.apache.activemq.usage.SystemUsage)6 MutableSpan (brave.handler.MutableSpan)5 MessageNotWriteableException (javax.jms.MessageNotWriteableException)5