Search in sources :

Example 96 with Message

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

the class StoreQueueCursorOrderTest method testNoSetBatchWithUnOrderedFutureCurrentSync.

@Test
public void testNoSetBatchWithUnOrderedFutureCurrentSync() throws Exception {
    final int count = 2;
    final Message[] messages = new Message[count];
    final TestMessageStore queueMessageStore = new TestMessageStore(messages, destination);
    final ConsumerInfo consumerInfo = new ConsumerInfo();
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    consumerInfo.setExclusive(true);
    final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, null);
    queueMessageStore.start();
    queueMessageStore.registerIndexListener(null);
    QueueStorePrefetch underTest = new QueueStorePrefetch(queue, brokerService.getBroker());
    SystemUsage systemUsage = new SystemUsage();
    // ensure memory limit is reached
    systemUsage.getMemoryUsage().setLimit(messageBytesSize * 1);
    underTest.setSystemUsage(systemUsage);
    underTest.setEnableAudit(false);
    underTest.start();
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    ActiveMQTextMessage msg = getMessage(0);
    messages[1] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.setRecievedByDFBridge(true);
    final ActiveMQTextMessage msgRef = msg;
    FutureTask<Long> future = new FutureTask<Long>(new Runnable() {

        @Override
        public void run() {
            msgRef.getMessageId().setFutureOrSequenceLong(1L);
        }
    }, 1L) {
    };
    msg.getMessageId().setFutureOrSequenceLong(future);
    Executors.newSingleThreadExecutor().submit(future);
    underTest.addMessageLast(msg);
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    // second message will flip the cache but will be stored before the future task
    msg = getMessage(1);
    messages[0] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.getMessageId().setFutureOrSequenceLong(1L);
    underTest.addMessageLast(msg);
    assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
    assertEquals("setBatch unset", 0L, queueMessageStore.batch.get());
    int dequeueCount = 0;
    underTest.setMaxBatchSize(2);
    underTest.reset();
    while (underTest.hasNext() && dequeueCount < count) {
        MessageReference ref = underTest.next();
        ref.decrementReferenceCount();
        underTest.remove();
        LOG.info("Received message: {} with body: {}", ref.getMessageId(), ((ActiveMQTextMessage) ref.getMessage()).getText());
        assertEquals(dequeueCount++, ref.getMessageId().getProducerSequenceId());
    }
    underTest.release();
    assertEquals(count, dequeueCount);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) SystemUsage(org.apache.activemq.usage.SystemUsage) MessageReference(org.apache.activemq.broker.region.MessageReference) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) FutureTask(java.util.concurrent.FutureTask) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(org.apache.activemq.broker.region.Queue) Test(org.junit.Test)

Example 97 with Message

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

the class RecoverExpiredMessagesTest method sendSomeMessagesThatWillExpireIn5AndThenOne.

private void sendSomeMessagesThatWillExpireIn5AndThenOne() throws Exception {
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    int MESSAGE_COUNT = 10;
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setExpiration(System.currentTimeMillis() + 5000);
        message.setPersistent(true);
        connection.send(message);
    }
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(true);
    connection.send(message);
    expected.add(message.getMessageId().toString());
    connection.request(closeConnectionInfo(connectionInfo));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 98 with Message

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

the class FailoverTransportBrokerTest method createMessage.

protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination, int deliveryMode) {
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(deliveryMode == DeliveryMode.PERSISTENT);
    return message;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message)

Example 99 with Message

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

the class FanoutTransportBrokerTest method createMessage.

protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination, int deliveryMode) {
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(deliveryMode == DeliveryMode.PERSISTENT);
    return message;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message)

Example 100 with Message

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

the class MessageTestSupport method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    Message info = (Message) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setTransactionId(createTransactionId("TransactionId:3"));
    info.setOriginalDestination(createActiveMQDestination("OriginalDestination:4"));
    info.setMessageId(createMessageId("MessageId:5"));
    info.setOriginalTransactionId(createTransactionId("OriginalTransactionId:6"));
    info.setGroupID("GroupID:7");
    info.setGroupSequence(1);
    info.setCorrelationId("CorrelationId:8");
    info.setPersistent(true);
    info.setExpiration(1);
    info.setPriority((byte) 1);
    info.setReplyTo(createActiveMQDestination("ReplyTo:9"));
    info.setTimestamp(2);
    info.setType("Type:10");
    {
        byte[] data = "Content:11".getBytes();
        info.setContent(new org.apache.activemq.util.ByteSequence(data, 0, data.length));
    }
    {
        byte[] data = "MarshalledProperties:12".getBytes();
        info.setMarshalledProperties(new org.apache.activemq.util.ByteSequence(data, 0, data.length));
    }
    info.setDataStructure(createDataStructure("DataStructure:13"));
    info.setTargetConsumerId(createConsumerId("TargetConsumerId:14"));
    info.setCompressed(false);
    info.setRedeliveryCounter(2);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:15");
        }
        info.setBrokerPath(value);
    }
    info.setArrival(3);
    info.setUserID("UserID:16");
    info.setRecievedByDFBridge(true);
    info.setDroppable(false);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("Cluster:17");
        }
        info.setCluster(value);
    }
    info.setBrokerInTime(4);
    info.setBrokerOutTime(5);
}
Also used : Message(org.apache.activemq.command.Message)

Aggregations

Message (org.apache.activemq.command.Message)102 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)77 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)71 SessionInfo (org.apache.activemq.command.SessionInfo)71 ProducerInfo (org.apache.activemq.command.ProducerInfo)69 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)46 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)24 MessageAck (org.apache.activemq.command.MessageAck)15 XATransactionId (org.apache.activemq.command.XATransactionId)15 StubConnection (org.apache.activemq.broker.StubConnection)14 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)13 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)11 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)8 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 Response (org.apache.activemq.command.Response)7 Test (org.junit.Test)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)5