Search in sources :

Example 46 with ProducerInfo

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

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

use of org.apache.activemq.command.ProducerInfo 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)

Example 49 with ProducerInfo

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

the class ForwardingBridgeTest method testForwardMessageCompressed.

public void testForwardMessageCompressed() throws Exception {
    bridge.setUseCompression(true);
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo);
    Thread.sleep(1000);
    // Give forwarding bridge a chance to finish setting up
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    // Send the message to the local boker.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered via the remote.
    Message m = receiveMessage(connection2);
    assertNotNull(m);
    // Make sure its compressed now
    ActiveMQMessage message = (ActiveMQMessage) m;
    assertTrue(message.isCompressed());
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage)

Example 50 with ProducerInfo

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

the class ForwardingBridgeTest method testAddConsumerThenSend.

public void testAddConsumerThenSend() throws Exception {
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo);
    Thread.sleep(1000);
    // Give forwarding bridge a chance to finish setting up
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    // Send the message to the local boker.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered via the remote.
    Message m = receiveMessage(connection2);
    assertNotNull(m);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) StubConnection(org.apache.activemq.broker.StubConnection) 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