Search in sources :

Example 16 with MessageAck

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

the class FailoverTransportTest method testResponsesSentWhenRequestForIgnoredCommands.

@Test(timeout = 30000)
public void testResponsesSentWhenRequestForIgnoredCommands() throws Exception {
    this.transport = createTransport();
    assertNotNull(failoverTransport);
    MessageAck ack = new MessageAck();
    assertNotNull("Should have received a Response", this.transport.request(ack));
    RemoveInfo info = new RemoveInfo(new ConnectionId("2"));
    assertNotNull("Should have received a Response", this.transport.request(info));
}
Also used : ConnectionId(org.apache.activemq.command.ConnectionId) RemoveInfo(org.apache.activemq.command.RemoveInfo) MessageAck(org.apache.activemq.command.MessageAck) Test(org.junit.Test)

Example 17 with MessageAck

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

the class XARecoveryBrokerTest method testTopicPersistentPreparedAcksAvailableAfterRestartAndRollback.

public void testTopicPersistentPreparedAcksAvailableAfterRestartAndRollback() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TryTopic");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    connectionInfo.setClientId("durable");
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // setup durable subs
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    connection.send(consumerInfo);
    int numMessages = 4;
    for (int i = 0; i < numMessages; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    Message message = null;
    for (int i = 0; i < numMessages; i++) {
        message = receiveMessage(connection);
        assertNotNull(message);
    }
    // one ack with last received, mimic a beforeEnd synchronization
    MessageAck ack = createAck(consumerInfo, message, numMessages, MessageAck.STANDARD_ACK_TYPE);
    ack.setTransactionId(txid);
    connection.send(ack);
    connection.request(createPrepareTransaction(connectionInfo, txid));
    // restart the broker.
    restartBroker();
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    connectionInfo.setClientId("durable");
    connection.send(connectionInfo);
    // validate recovery
    TransactionInfo recoverInfo = new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER);
    DataArrayResponse dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo);
    assertEquals("there is a prepared tx", 1, dataArrayResponse.getData().length);
    assertEquals("it matches", txid, dataArrayResponse.getData()[0]);
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    connection.send(consumerInfo);
    // no redelivery, exactly once semantics while prepared
    message = receiveMessage(connection);
    assertNull(message);
    assertNoMessagesLeft(connection);
    // rollback so we get redelivery
    connection.request(createRollbackTransaction(connectionInfo, txid));
    LOG.info("new tx for redelivery");
    txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < numMessages; i++) {
        message = receiveMessage(connection);
        assertNotNull("unexpected null on:" + i, message);
    }
    ack = createAck(consumerInfo, message, numMessages, MessageAck.STANDARD_ACK_TYPE);
    ack.setTransactionId(txid);
    connection.send(ack);
    // Commit
    connection.request(createCommitTransaction1Phase(connectionInfo, txid));
    // validate recovery complete
    dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo);
    assertEquals("there are no prepared tx", 0, dataArrayResponse.getData().length);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) TransactionInfo(org.apache.activemq.command.TransactionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) DataArrayResponse(org.apache.activemq.command.DataArrayResponse)

Example 18 with MessageAck

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

the class XARecoveryBrokerTest method testQueuePersistentCommittedAcksNotLostOnRestart.

public void testQueuePersistentCommittedAcksNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = createDestination();
    // 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);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    ConsumerInfo consumerInfo;
    Message m = null;
    for (ActiveMQDestination dest : destinationList(destination)) {
        // Setup the consumer and receive the message.
        consumerInfo = createConsumerInfo(sessionInfo, dest);
        connection.send(consumerInfo);
        for (int i = 0; i < 4; i++) {
            m = receiveMessage(connection);
            assertNotNull(m);
        }
        MessageAck ack = createAck(consumerInfo, m, 4, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.send(ack);
    }
    // Commit
    connection.request(createCommitTransaction1Phase(connectionInfo, txid));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // No messages should be delivered.
    assertNoMessagesLeft(connection);
    m = receiveMessage(connection);
    assertNull(m);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 19 with MessageAck

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

the class RecoverExpiredMessagesTest method consumeExpected.

private void consumeExpected() throws Exception {
    // Setup the consumer and receive the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    Message m = receiveMessage(connection);
    assertNotNull("Should have received message " + expected.get(0) + " by now!", m);
    assertEquals(expected.get(0), m.getMessageId().toString());
    MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
    connection.send(ack);
    assertNoMessagesLeft(connection);
    connection.request(closeConnectionInfo(connectionInfo));
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 20 with MessageAck

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

the class BrokerNetworkWithStuckMessagesTest method createAck.

protected MessageAck createAck(ConsumerInfo consumerInfo, Message msg, int count, byte ackType) {
    MessageAck ack = new MessageAck();
    ack.setAckType(ackType);
    ack.setConsumerId(consumerInfo.getConsumerId());
    ack.setDestination(msg.getDestination());
    ack.setLastMessageId(msg.getMessageId());
    ack.setMessageCount(count);
    return ack;
}
Also used : MessageAck(org.apache.activemq.command.MessageAck)

Aggregations

MessageAck (org.apache.activemq.command.MessageAck)38 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)15 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)15 Message (org.apache.activemq.command.Message)15 ProducerInfo (org.apache.activemq.command.ProducerInfo)14 SessionInfo (org.apache.activemq.command.SessionInfo)14 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)12 XATransactionId (org.apache.activemq.command.XATransactionId)9 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)5 TransactionInfo (org.apache.activemq.command.TransactionInfo)5 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)4 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)3 ConnectionId (org.apache.activemq.command.ConnectionId)2 RemoveInfo (org.apache.activemq.command.RemoveInfo)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Vector (java.util.Vector)1 CountDownLatch (java.util.concurrent.CountDownLatch)1