Search in sources :

Example 41 with Message

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

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

the class AdvisoryBrokerTest method testConnectionAdvisories.

public void testConnectionAdvisories() throws Exception {
    ActiveMQDestination destination = AdvisorySupport.getConnectionAdvisoryTopic();
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    // We should get an advisory of our own connection.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo1.getConnectionId());
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connection2.send(connectionInfo2);
    // We should get an advisory of the second connection.
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo2.getConnectionId());
    // Close the second connection.
    connection2.send(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the second connection closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), connectionInfo2.getConnectionId());
    assertNoMessagesLeft(connection1);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) RemoveInfo(org.apache.activemq.command.RemoveInfo) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 43 with Message

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

the class AdvisoryBrokerTest method testConsumerAdvisories.

public void testConsumerAdvisories() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getConsumerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    // We should not see and advisory for the advisory consumer.
    assertNoMessagesLeft(connection1);
    // Setup a second consumer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
    consumerInfo1.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // We should get an advisory of the new consumer.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConsumerInfo) m1.getDataStructure()).getConsumerId(), consumerInfo2.getConsumerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the consumer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), consumerInfo2.getConsumerId());
    assertNoMessagesLeft(connection2);
}
Also used : 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 44 with Message

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

the class AdvisoryBrokerTest method testProducerAdvisories.

public void testProducerAdvisories() 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);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    assertNoMessagesLeft(connection1);
    // 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);
    // We should get an advisory of the new producer.
    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 : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) 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 45 with Message

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

the class QueueOptimizedDispatchExceptionTest method TestOptimizedDispatchCME.

@Test
public void TestOptimizedDispatchCME() throws Exception {
    final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
    final ConnectionContext contextNotInTx = new ConnectionContext();
    contextNotInTx.setConnection(new Connection() {

        @Override
        public void stop() throws Exception {
        }

        @Override
        public void start() throws Exception {
        }

        @Override
        public void updateClient(ConnectionControl control) {
        }

        @Override
        public void serviceExceptionAsync(IOException e) {
        }

        @Override
        public void serviceException(Throwable error) {
        }

        @Override
        public Response service(Command command) {
            return null;
        }

        @Override
        public boolean isSlow() {
            return false;
        }

        @Override
        public boolean isNetworkConnection() {
            return false;
        }

        @Override
        public boolean isManageable() {
            return false;
        }

        @Override
        public boolean isFaultTolerantConnection() {
            return false;
        }

        @Override
        public boolean isConnected() {
            return true;
        }

        @Override
        public boolean isBlocked() {
            return false;
        }

        @Override
        public boolean isActive() {
            return false;
        }

        @Override
        public ConnectionStatistics getStatistics() {
            return null;
        }

        @Override
        public String getRemoteAddress() {
            return null;
        }

        @Override
        public int getDispatchQueueSize() {
            return 0;
        }

        @Override
        public Connector getConnector() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getConnectionId() {
            return null;
        }

        @Override
        public void dispatchSync(Command message) {
        }

        @Override
        public void dispatchAsync(Command command) {
        }

        @Override
        public int getActiveTransactionCount() {
            return 0;
        }

        @Override
        public Long getOldestActiveTransactionDuration() {
            return null;
        }
    });
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
    final MockMemoryUsage usage = new MockMemoryUsage();
    queue.setOptimizedDispatch(true);
    queue.initialize();
    queue.start();
    queue.memoryUsage = usage;
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    ProducerInfo producerInfo = new ProducerInfo();
    ProducerState producerState = new ProducerState(producerInfo);
    producerExchange.setProducerState(producerState);
    producerExchange.setConnectionContext(contextNotInTx);
    // populate the queue store, exceed memory limit so that cache is disabled
    for (int i = 0; i < count; i++) {
        Message message = getMessage(i);
        queue.send(producerExchange, message);
    }
    usage.setFull(false);
    try {
        queue.wakeup();
    } catch (Exception e) {
        LOG.error("Queue threw an unexpected exception: " + e.toString());
        fail("Should not throw an exception.");
    }
}
Also used : MessageStore(org.apache.activemq.store.MessageStore) Connector(org.apache.activemq.broker.Connector) ProducerBrokerExchange(org.apache.activemq.broker.ProducerBrokerExchange) ProducerInfo(org.apache.activemq.command.ProducerInfo) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) Connection(org.apache.activemq.broker.Connection) IOException(java.io.IOException) IOException(java.io.IOException) Response(org.apache.activemq.command.Response) ConnectionControl(org.apache.activemq.command.ConnectionControl) Command(org.apache.activemq.command.Command) ProducerState(org.apache.activemq.state.ProducerState) ConnectionContext(org.apache.activemq.broker.ConnectionContext) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) Test(org.junit.Test)

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