Search in sources :

Example 56 with ProducerInfo

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

the class XARecoveryBrokerTest method testTopicPreparedTransactionRecoveredOnRestart.

public void testTopicPreparedTransactionRecoveredOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TryTopic");
    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);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    connection.send(consumerInfo);
    // Prepare 4 message sends.
    for (int i = 0; i < 4; i++) {
        // Begin the transaction.
        XATransactionId txid = createXATransaction(sessionInfo);
        connection.send(createBeginTransaction(connectionInfo, txid));
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
        // Prepare
        connection.send(createPrepareTransaction(connectionInfo, txid));
    }
    // Since prepared but not committed.. they should not get delivered.
    assertNull(receiveMessage(connection));
    assertNoMessagesLeft(connection);
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and try receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    connectionInfo.setClientId("durable");
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    connection.send(consumerInfo);
    // Since prepared but not committed.. they should not get delivered.
    assertNull(receiveMessage(connection));
    assertNoMessagesLeft(connection);
    Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    DataArrayResponse dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // ensure we can close a connection with prepared transactions
    connection.request(closeConnectionInfo(connectionInfo));
    // open again  to deliver outcome
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    connectionInfo.setClientId("durable");
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    connection.send(consumerInfo);
    // Commit the prepared transactions.
    for (int i = 0; i < dar.getData().length; i++) {
        connection.request(createCommitTransaction2Phase(connectionInfo, (TransactionId) dar.getData()[i]));
    }
    // We should get the committed transactions.
    for (int i = 0; i < expectedMessageCount(4, destination); i++) {
        Message m = receiveMessage(connection, TimeUnit.SECONDS.toMillis(10));
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}
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) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) XATransactionId(org.apache.activemq.command.XATransactionId) TransactionId(org.apache.activemq.command.TransactionId) Response(org.apache.activemq.command.Response) DataArrayResponse(org.apache.activemq.command.DataArrayResponse) TransactionInfo(org.apache.activemq.command.TransactionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) DataArrayResponse(org.apache.activemq.command.DataArrayResponse)

Example 57 with ProducerInfo

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

the class XARecoveryBrokerTest method testPreparedTransactionRecoveredOnRestart.

public void testPreparedTransactionRecoveredOnRestart() 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);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Prepare 4 message sends.
    for (int i = 0; i < 4; i++) {
        // Begin the transaction.
        XATransactionId txid = createXATransaction(sessionInfo);
        connection.send(createBeginTransaction(connectionInfo, txid));
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
        // Prepare
        connection.send(createPrepareTransaction(connectionInfo, txid));
    }
    // Since prepared but not committed.. they should not get delivered.
    assertNull(receiveMessage(connection));
    assertNoMessagesLeft(connection);
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and try receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Since prepared but not committed.. they should not get delivered.
    assertNull(receiveMessage(connection));
    assertNoMessagesLeft(connection);
    Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    DataArrayResponse dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // ensure we can close a connection with prepared transactions
    connection.request(closeConnectionInfo(connectionInfo));
    // open again  to deliver outcome
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Commit the prepared transactions.
    for (int i = 0; i < dar.getData().length; i++) {
        TransactionId transactionId = (TransactionId) dar.getData()[i];
        LOG.info("commit: " + transactionId);
        connection.request(createCommitTransaction2Phase(connectionInfo, transactionId));
    }
    // We should get the committed transactions.
    final int countToReceive = expectedMessageCount(4, destination);
    for (int i = 0; i < countToReceive; i++) {
        Message m = receiveMessage(connection, TimeUnit.SECONDS.toMillis(10));
        LOG.info("received: " + m);
        assertNotNull("Got non null message: " + i, m);
    }
    assertNoMessagesLeft(connection);
    assertEmptyDLQ();
}
Also used : 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) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) XATransactionId(org.apache.activemq.command.XATransactionId) TransactionId(org.apache.activemq.command.TransactionId) Response(org.apache.activemq.command.Response) DataArrayResponse(org.apache.activemq.command.DataArrayResponse) TransactionInfo(org.apache.activemq.command.TransactionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) DataArrayResponse(org.apache.activemq.command.DataArrayResponse)

Example 58 with ProducerInfo

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

the class AdvisoryBrokerTest method testProducerAdvisoriesReplayedOnlyTargetNewConsumer.

public void testProducerAdvisoriesReplayedOnlyTargetNewConsumer() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Create the first consumer..
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Create the 2nd consumer..
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(100);
    connection2.send(consumerInfo2);
    // The second consumer should se a replay
    m1 = receiveMessage(connection2);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // But the first consumer should not see the replay.
    assertNoMessagesLeft(connection1);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) StubConnection(org.apache.activemq.broker.StubConnection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 59 with ProducerInfo

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

the class AdvisoryBrokerTest method testProducerAdvisoriesReplayed.

public void testProducerAdvisoriesReplayed() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // Create the advisory consumer.. it should see the previous producer
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the producer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), producerInfo2.getProducerId());
    assertNoMessagesLeft(connection2);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) RemoveInfo(org.apache.activemq.command.RemoveInfo) StubConnection(org.apache.activemq.broker.StubConnection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 60 with ProducerInfo

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

the class BrokerTest method testAddConsumerThenSend.

public void testAddConsumerThenSend() throws Exception {
    // Start a producer and consumer
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    destination = createDestinationInfo(connection, connectionInfo, destinationType);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered.
    Message m = receiveMessage(connection);
    assertNotNull(m);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Aggregations

ProducerInfo (org.apache.activemq.command.ProducerInfo)95 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)72 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)72 SessionInfo (org.apache.activemq.command.SessionInfo)72 Message (org.apache.activemq.command.Message)69 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)42 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)18 XATransactionId (org.apache.activemq.command.XATransactionId)15 StubConnection (org.apache.activemq.broker.StubConnection)14 MessageAck (org.apache.activemq.command.MessageAck)14 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)11 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 Response (org.apache.activemq.command.Response)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)4 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)4 TransactionId (org.apache.activemq.command.TransactionId)4