Search in sources :

Example 86 with ProducerInfo

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

the class UdpTestSupport method assertSendTextMessage.

protected void assertSendTextMessage(ActiveMQDestination destination, String text) throws MessageNotWriteableException {
    large = true;
    ActiveMQTextMessage expected = new ActiveMQTextMessage();
    expected.setText(text);
    expected.setDestination(destination);
    try {
        LOG.info("About to send message of type: " + expected.getClass());
        producer.oneway(expected);
        // lets send a dummy command to ensure things don't block if we
        // discard the last one
        // keepalive does not have a commandId...
        // producer.oneway(new KeepAliveInfo());
        producer.oneway(new ProducerInfo());
        producer.oneway(new ProducerInfo());
        Command received = assertCommandReceived();
        assertTrue("Should have received an ActiveMQTextMessage but was: " + received, received instanceof ActiveMQTextMessage);
        ActiveMQTextMessage actual = (ActiveMQTextMessage) received;
        assertEquals("getDestination", expected.getDestination(), actual.getDestination());
        assertEquals("getText", expected.getText(), actual.getText());
        LOG.info("Received text message with: " + actual.getText().length() + " character(s)");
    } catch (Exception e) {
        LOG.info("Caught: " + e);
        e.printStackTrace();
        fail("Failed to send to transport: " + e);
    }
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) Command(org.apache.activemq.command.Command) IOException(java.io.IOException) MessageNotWriteableException(javax.jms.MessageNotWriteableException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 87 with ProducerInfo

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

the class QueueDuplicatesFromStoreTest method doTestNoDuplicateAfterCacheFullAndAcked.

public void doTestNoDuplicateAfterCacheFullAndAcked(final int auditDepth) throws Exception {
    final PersistenceAdapter persistenceAdapter = brokerService.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
    final ConnectionContext contextNotInTx = new ConnectionContext();
    final ConsumerInfo consumerInfo = new ConsumerInfo();
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    consumerInfo.setExclusive(true);
    final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, brokerService.getTaskRunnerFactory());
    // a workaround for this issue
    // queue.setUseCache(false);
    queue.systemUsage.getMemoryUsage().setLimit(1024 * 1024 * 10);
    queue.setMaxAuditDepth(auditDepth);
    queue.initialize();
    queue.start();
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    ProducerInfo producerInfo = new ProducerInfo();
    ProducerState producerState = new ProducerState(producerInfo);
    producerExchange.setProducerState(producerState);
    producerExchange.setConnectionContext(contextNotInTx);
    final CountDownLatch receivedLatch = new CountDownLatch(count);
    final AtomicLong ackedCount = new AtomicLong(0);
    final AtomicLong enqueueCounter = new AtomicLong(0);
    final Vector<String> errors = new Vector<>();
    // 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);
    }
    assertEquals("store count is correct", count, queueMessageStore.getMessageCount());
    // pull from store in small windows
    Subscription subscription = new Subscription() {

        private SubscriptionStatistics subscriptionStatistics = new SubscriptionStatistics();

        @Override
        public long getPendingMessageSize() {
            return 0;
        }

        @Override
        public void add(MessageReference node) throws Exception {
            if (enqueueCounter.get() != node.getMessageId().getProducerSequenceId()) {
                errors.add("Not in sequence at: " + enqueueCounter.get() + ", received: " + node.getMessageId().getProducerSequenceId());
            }
            assertEquals("is in order", enqueueCounter.get(), node.getMessageId().getProducerSequenceId());
            receivedLatch.countDown();
            enqueueCounter.incrementAndGet();
            node.decrementReferenceCount();
        }

        @Override
        public void add(ConnectionContext context, Destination destination) throws Exception {
        }

        @Override
        public int countBeforeFull() {
            if (isFull()) {
                return 0;
            } else {
                return fullWindow - (int) (enqueueCounter.get() - ackedCount.get());
            }
        }

        @Override
        public void destroy() {
        }

        @Override
        public void gc() {
        }

        @Override
        public ConsumerInfo getConsumerInfo() {
            return consumerInfo;
        }

        @Override
        public ConnectionContext getContext() {
            return null;
        }

        @Override
        public long getDequeueCounter() {
            return 0;
        }

        @Override
        public long getDispatchedCounter() {
            return 0;
        }

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

        @Override
        public long getEnqueueCounter() {
            return 0;
        }

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

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

        @Override
        public ObjectName getObjectName() {
            return null;
        }

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

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

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

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

        @Override
        public boolean isFull() {
            return (enqueueCounter.get() - ackedCount.get()) >= fullWindow;
        }

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

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

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

        @Override
        public boolean matches(MessageReference node, MessageEvaluationContext context) throws IOException {
            return true;
        }

        @Override
        public boolean matches(ActiveMQDestination destination) {
            return true;
        }

        @Override
        public void processMessageDispatchNotification(MessageDispatchNotification mdn) throws Exception {
        }

        @Override
        public Response pullMessage(ConnectionContext context, MessagePull pull) throws Exception {
            return null;
        }

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

        @Override
        public List<MessageReference> remove(ConnectionContext context, Destination destination) throws Exception {
            return null;
        }

        @Override
        public void setObjectName(ObjectName objectName) {
        }

        @Override
        public void setSelector(String selector) throws InvalidSelectorException, UnsupportedOperationException {
        }

        @Override
        public void updateConsumerPrefetch(int newPrefetch) {
        }

        @Override
        public boolean addRecoveredMessage(ConnectionContext context, MessageReference message) throws Exception {
            return false;
        }

        @Override
        public ActiveMQDestination getActiveMQDestination() {
            return destination;
        }

        @Override
        public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
        }

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

        @Override
        public void setCursorMemoryHighWaterMark(int cursorMemoryHighWaterMark) {
        }

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

        @Override
        public void unmatched(MessageReference node) throws IOException {
        }

        @Override
        public long getTimeOfLastMessageAck() {
            return 0;
        }

        @Override
        public long getConsumedCount() {
            return 0;
        }

        @Override
        public void incrementConsumedCount() {
        }

        @Override
        public void resetConsumedCount() {
        }

        @Override
        public SubscriptionStatistics getSubscriptionStatistics() {
            return subscriptionStatistics;
        }

        @Override
        public long getInFlightMessageSize() {
            return subscriptionStatistics.getInflightMessageSize().getTotalSize();
        }
    };
    queue.addSubscription(contextNotInTx, subscription);
    int removeIndex = 0;
    do {
        // Simulate periodic acks in small but recent windows
        long receivedCount = enqueueCounter.get();
        if (receivedCount > ackStartIndex) {
            if (receivedCount >= removeIndex + ackWindow) {
                for (int j = 0; j < ackBatchSize; j++, removeIndex++) {
                    ackedCount.incrementAndGet();
                    MessageAck ack = new MessageAck();
                    ack.setLastMessageId(new MessageId(mesageIdRoot + removeIndex));
                    ack.setMessageCount(1);
                    queue.removeMessage(contextNotInTx, subscription, new IndirectMessageReference(getMessage(removeIndex)), ack);
                    queue.wakeup();
                }
                if (removeIndex % 1000 == 0) {
                    LOG.info("acked: " + removeIndex);
                    persistenceAdapter.checkpoint(true);
                }
            }
        }
    } while (!receivedLatch.await(0, TimeUnit.MILLISECONDS) && errors.isEmpty());
    assertTrue("There are no errors: " + errors, errors.isEmpty());
    assertEquals(count, enqueueCounter.get());
    assertEquals("store count is correct", count - removeIndex, queueMessageStore.getMessageCount());
}
Also used : MessageStore(org.apache.activemq.store.MessageStore) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) MessagePull(org.apache.activemq.command.MessagePull) ProducerState(org.apache.activemq.state.ProducerState) ConnectionContext(org.apache.activemq.broker.ConnectionContext) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Vector(java.util.Vector) ProducerBrokerExchange(org.apache.activemq.broker.ProducerBrokerExchange) ProducerInfo(org.apache.activemq.command.ProducerInfo) MessageEvaluationContext(org.apache.activemq.filter.MessageEvaluationContext) MessageAck(org.apache.activemq.command.MessageAck) MessageDispatchNotification(org.apache.activemq.command.MessageDispatchNotification) CountDownLatch(java.util.concurrent.CountDownLatch) ObjectName(javax.management.ObjectName) AtomicLong(java.util.concurrent.atomic.AtomicLong) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) MessageId(org.apache.activemq.command.MessageId)

Example 88 with ProducerInfo

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

the class RecoverExpiredMessagesTest method sendSomeMessagesThatWillExpireIn5AndThenOne.

private void sendSomeMessagesThatWillExpireIn5AndThenOne() throws Exception {
    // 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);
    int MESSAGE_COUNT = 10;
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setExpiration(System.currentTimeMillis() + 5000);
        message.setPersistent(true);
        connection.send(message);
    }
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(true);
    connection.send(message);
    expected.add(message.getMessageId().toString());
    connection.request(closeConnectionInfo(connectionInfo));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 89 with ProducerInfo

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

the class FailoverTransportBrokerTest method testPublisherFailsOver.

@Test
public void testPublisherFailsOver() throws Exception {
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a failover publisher.
    LOG.info("Starting the failover connection.");
    StubConnection connection3 = createFailoverConnection(null);
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    // The message will be sent to one of the brokers.
    FailoverTransport ft = connection3.getTransport().narrow(FailoverTransport.class);
    // See which broker we were connected to.
    StubConnection connectionA;
    StubConnection connectionB;
    EmbeddedJMS serverA;
    if (new URI(newURI(0)).equals(ft.getConnectedTransportURI())) {
        connectionA = connection1;
        connectionB = connection2;
        serverA = server;
    } else {
        connectionA = connection2;
        connectionB = connection1;
        serverA = remoteServer;
    }
    Assert.assertNotNull(receiveMessage(connectionA));
    assertNoMessagesLeft(connectionB);
    // Dispose the server so that it fails over to the other server.
    LOG.info("Disconnecting the active connection");
    serverA.stop();
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    Assert.assertNotNull(receiveMessage(connectionB));
    assertNoMessagesLeft(connectionA);
}
Also used : EmbeddedJMS(org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) URI(java.net.URI) Test(org.junit.Test) OpenwireArtemisBaseTest(org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)

Example 90 with ProducerInfo

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

the class FanoutTransportBrokerTest method testPublisherWaitsForServerToBeUp.

/*
   public void initCombosForTestPublisherWaitsForServerToBeUp() {
      addCombinationValues("deliveryMode", new Object[]{Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
      addCombinationValues("destination", new Object[]{new ActiveMQTopic("TEST")});
   }
*/
@Test
public void testPublisherWaitsForServerToBeUp() throws Exception {
    if (name.getMethodName().contains("test-0") || name.getMethodName().contains("test-2")) {
        System.out.println("Discarding invalid test: " + name.getMethodName());
        return;
    }
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a fanout publisher.
    LOG.info("Starting the fanout connection.");
    final StubConnection connection3 = createFanoutConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    final ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    Assert.assertNotNull(receiveMessage(connection1));
    assertNoMessagesLeft(connection1);
    Assert.assertNotNull(receiveMessage(connection2));
    assertNoMessagesLeft(connection2);
    final CountDownLatch publishDone = new CountDownLatch(1);
    // The MockTransport is on the remote connection.
    // Slip in a new transport filter after the MockTransport
    MockTransport mt = connection3.getTransport().narrow(MockTransport.class);
    mt.install(new TransportFilter(mt.getNext()) {

        @Override
        public void oneway(Object command) throws IOException {
            LOG.info("Dropping: " + command);
        // just eat it! to simulate a recent failure.
        }
    });
    // Send a message (async) as this will block
    new Thread() {

        @Override
        public void run() {
            // Send the message using the fail over publisher.
            try {
                connection3.request(createMessage(producerInfo3, destination, deliveryMode));
            } catch (Throwable e) {
                e.printStackTrace();
            }
            publishDone.countDown();
        }
    }.start();
    // Assert that we block:
    Assert.assertFalse(publishDone.await(3, TimeUnit.SECONDS));
    // Restart the remote server. State should be re-played and the publish
    // should continue.
    LOG.info("Restarting Broker");
    restartRemoteBroker();
    LOG.info("Broker Restarted");
    // This should reconnect, and resend
    Assert.assertTrue(publishDone.await(20, TimeUnit.SECONDS));
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) SessionInfo(org.apache.activemq.command.SessionInfo) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) TransportFilter(org.apache.activemq.transport.TransportFilter) StubConnection(org.apache.activemq.broker.StubConnection) MockTransport(org.apache.activemq.transport.mock.MockTransport) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) Test(org.junit.Test) OpenwireArtemisBaseTest(org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)

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