Search in sources :

Example 1 with ArtemisBrokerWrapper

use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.

the class BrokerTest method testQueueAckRemovesMessage.

public void testQueueAckRemovesMessage() 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);
    Message message1 = createMessage(producerInfo, destination, deliveryMode);
    Message message2 = createMessage(producerInfo, destination, deliveryMode);
    connection.send(message1);
    connection.send(message2);
    // Make sure the message was delivered.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.request(consumerInfo);
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m.getMessageId(), message1.getMessageId());
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    long messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 2);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.DELIVERED_ACK_TYPE));
    messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 2);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // give some time for broker to count down
    Thread.sleep(2000);
    messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 1);
}
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) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)

Example 2 with ArtemisBrokerWrapper

use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.

the class BrokerService method makeSureDestinationExists.

public void makeSureDestinationExists(ActiveMQDestination activemqDestination) throws Exception {
    ArtemisBrokerWrapper hqBroker = (ArtemisBrokerWrapper) this.broker;
    // it can be null
    if (activemqDestination == null) {
        return;
    }
    if (activemqDestination.isQueue()) {
        String qname = activemqDestination.getPhysicalName();
        System.out.println("physical name: " + qname);
        hqBroker.makeSureQueueExists(qname);
    }
}
Also used : ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)

Example 3 with ArtemisBrokerWrapper

use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.

the class JMSConsumerTest method createQueueControl.

private QueueControl createQueueControl(String destName) throws Exception {
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    MBeanServer beanServer = wrapper.getMbeanServer();
    SimpleString address = new SimpleString(destName);
    ObjectName objName = ObjectNameBuilder.DEFAULT.getQueueObjectName(address, address, RoutingType.ANYCAST);
    return MBeanServerInvocationHandler.newProxyInstance(beanServer, objName, QueueControl.class, false);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 4 with ArtemisBrokerWrapper

use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.

the class RemoveDestinationTest method destinationPresentInAdminView.

private boolean destinationPresentInAdminView(ActiveMQTopic amqTopic) throws Exception {
    boolean found = false;
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    PostOffice po = wrapper.getServer().getPostOffice();
    Set<SimpleString> addressSet = po.getAddresses();
    Iterator<SimpleString> iter = addressSet.iterator();
    String addressToFind = amqTopic.getPhysicalName();
    while (iter.hasNext()) {
        if (addressToFind.equals(iter.next().toString())) {
            found = true;
            break;
        }
    }
    return found;
}
Also used : PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)

Example 5 with ArtemisBrokerWrapper

use of org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper in project activemq-artemis by apache.

the class OptimizedAckTest method testReceivedMessageNotInFlightAfterScheduledAckFires.

public void testReceivedMessageNotInFlightAfterScheduledAckFires() throws Exception {
    connection.setOptimizedAckScheduledAckInterval(TimeUnit.SECONDS.toMillis(10));
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
    assertTrue("After delay the scheduled ack should ack all inflight.", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("inflight count: " + coreQueue.getDeliveringCount());
            return 0 == coreQueue.getDeliveringCount();
        }
    }));
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) MessageConsumer(javax.jms.MessageConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Session(javax.jms.Session)

Aggregations

ArtemisBrokerWrapper (org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 MessageConsumer (javax.jms.MessageConsumer)3 MessageProducer (javax.jms.MessageProducer)3 Queue (javax.jms.Queue)3 Session (javax.jms.Session)3 Binding (org.apache.activemq.artemis.core.postoffice.Binding)3 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)3 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)2 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)2 Message (org.apache.activemq.command.Message)2 ProducerInfo (org.apache.activemq.command.ProducerInfo)2 SessionInfo (org.apache.activemq.command.SessionInfo)2 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)1 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)1 MessageAck (org.apache.activemq.command.MessageAck)1