Search in sources :

Example 21 with Response

use of org.apache.activemq.command.Response 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 22 with Response

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

the class StubConnection method request.

public Response request(Command command) throws Exception {
    if (command instanceof Message) {
        Message message = (Message) command;
        message.setProducerId(message.getMessageId().getProducerId());
    }
    command.setResponseRequired(true);
    if (connection != null) {
        Response response = connection.service(command);
        if (response != null && response.isException()) {
            ExceptionResponse er = (ExceptionResponse) response;
            throw JMSExceptionSupport.create(er.getException());
        }
        return response;
    } else if (transport != null) {
        Response response = (Response) transport.request(command);
        if (response != null && response.isException()) {
            ExceptionResponse er = (ExceptionResponse) response;
            throw JMSExceptionSupport.create(er.getException());
        }
        return response;
    }
    return null;
}
Also used : Response(org.apache.activemq.command.Response) ExceptionResponse(org.apache.activemq.command.ExceptionResponse) ExceptionResponse(org.apache.activemq.command.ExceptionResponse) Message(org.apache.activemq.command.Message)

Example 23 with Response

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

the class AMQSession method sendShouldBlockProducer.

private void sendShouldBlockProducer(final ProducerInfo producerInfo, final Message messageSend, final boolean sendProducerAck, final PagingStore store, final ActiveMQDestination dest, final AtomicInteger count, final org.apache.activemq.artemis.api.core.Message coreMsg, final SimpleString address) throws ResourceAllocationException {
    if (!store.checkMemory(() -> {
        Exception exceptionToSend = null;
        try {
            getCoreSession().send(coreMsg, false, dest.isTemporary());
        } catch (Exception e) {
            logger.warn(e.getMessage(), e);
            exceptionToSend = e;
        }
        connection.enableTtl();
        if (count == null || count.decrementAndGet() == 0) {
            if (exceptionToSend != null) {
                this.connection.getContext().setDontSendReponse(false);
                connection.sendException(exceptionToSend);
            } else {
                server.getStorageManager().afterCompleteOperations(new IOCallback() {

                    @Override
                    public void done() {
                        if (sendProducerAck) {
                            try {
                                ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), messageSend.getSize());
                                connection.dispatchAsync(ack);
                            } catch (Exception e) {
                                connection.getContext().setDontSendReponse(false);
                                ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e);
                                connection.sendException(e);
                            }
                        } else {
                            connection.getContext().setDontSendReponse(false);
                            try {
                                Response response = new Response();
                                response.setCorrelationId(messageSend.getCommandId());
                                connection.dispatchAsync(response);
                            } catch (Exception e) {
                                ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e);
                                connection.sendException(e);
                            }
                        }
                    }

                    @Override
                    public void onError(int errorCode, String errorMessage) {
                        try {
                            final IOException e = new IOException(errorMessage);
                            ActiveMQServerLogger.LOGGER.warn(errorMessage);
                            connection.serviceException(e);
                        } catch (Exception ex) {
                            ActiveMQServerLogger.LOGGER.debug(ex);
                        }
                    }
                });
            }
        }
    })) {
        this.connection.getContext().setDontSendReponse(false);
        connection.enableTtl();
        throw new ResourceAllocationException("Queue is full " + address);
    }
}
Also used : Response(org.apache.activemq.command.Response) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) IOException(java.io.IOException) ResourceAllocationException(javax.jms.ResourceAllocationException) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) ProducerAck(org.apache.activemq.command.ProducerAck) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) IOException(java.io.IOException) ResourceAllocationException(javax.jms.ResourceAllocationException)

Example 24 with Response

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

the class ResponseTest method createObject.

@Override
public Object createObject() throws Exception {
    Response info = new Response();
    populateObject(info);
    return info;
}
Also used : Response(org.apache.activemq.command.Response)

Example 25 with Response

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

the class ResponseTest method createObject.

@Override
public Object createObject() throws Exception {
    Response info = new Response();
    populateObject(info);
    return info;
}
Also used : Response(org.apache.activemq.command.Response)

Aggregations

Response (org.apache.activemq.command.Response)32 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)7 Message (org.apache.activemq.command.Message)7 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)6 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)5 ProducerInfo (org.apache.activemq.command.ProducerInfo)5 IOException (java.io.IOException)4 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 ExceptionResponse (org.apache.activemq.command.ExceptionResponse)4 SessionInfo (org.apache.activemq.command.SessionInfo)4 TransactionId (org.apache.activemq.command.TransactionId)4 TransactionInfo (org.apache.activemq.command.TransactionInfo)4 XATransactionId (org.apache.activemq.command.XATransactionId)4 Command (org.apache.activemq.command.Command)3 Test (org.junit.Test)3 InvalidDestinationException (javax.jms.InvalidDestinationException)2 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)2 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)2 ControlCommand (org.apache.activemq.command.ControlCommand)2 FlushCommand (org.apache.activemq.command.FlushCommand)2