Search in sources :

Example 6 with ConsumerControl

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

the class ConsumerControlTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConsumerControl info = (ConsumerControl) object;
    info.setClose(true);
    info.setConsumerId(createConsumerId("ConsumerId:1"));
    info.setPrefetch(1);
    info.setFlush(false);
    info.setStart(true);
    info.setStop(false);
}
Also used : ConsumerControl(org.apache.activemq.command.ConsumerControl)

Example 7 with ConsumerControl

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

the class ConsumerControlTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConsumerControl info = (ConsumerControl) object;
    info.setClose(true);
    info.setConsumerId(createConsumerId("ConsumerId:1"));
    info.setPrefetch(1);
    info.setFlush(false);
    info.setStart(true);
    info.setStop(false);
}
Also used : ConsumerControl(org.apache.activemq.command.ConsumerControl)

Example 8 with ConsumerControl

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

the class ConsumerControlTest method createObject.

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

Example 9 with ConsumerControl

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

the class ZeroPrefetchConsumerTest method testBrokerZeroPrefetchConfigWithConsumerControl.

// https://issues.apache.org/jira/browse/AMQ-4234
// https://issues.apache.org/jira/browse/AMQ-4235
public void testBrokerZeroPrefetchConfigWithConsumerControl() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(brokerZeroQueue);
    assertEquals("broker config prefetch in effect", 0, consumer.info.getCurrentPrefetchSize());
    // verify sub view broker
    // I comment out this because it checks broker internal
    // which doesn't apply to artemis broker.
    // Subscription sub = broker.getRegionBroker().getDestinationMap().get(ActiveMQDestination.transform(brokerZeroQueue)).getConsumers().get(0);
    // assertEquals("broker sub prefetch is correct", 0, sub.getConsumerInfo().getCurrentPrefetchSize());
    // manipulate Prefetch (like failover and stomp)
    ConsumerControl consumerControl = new ConsumerControl();
    consumerControl.setConsumerId(consumer.info.getConsumerId());
    consumerControl.setDestination(ActiveMQDestination.transform(brokerZeroQueue));
    // default for a q
    consumerControl.setPrefetch(1000);
    Object reply = ((ActiveMQConnection) connection).getTransport().request(consumerControl);
    assertTrue("good request", !(reply instanceof ExceptionResponse));
    assertEquals("broker config prefetch in effect", 0, consumer.info.getCurrentPrefetchSize());
}
Also used : ExceptionResponse(org.apache.activemq.command.ExceptionResponse) ConsumerControl(org.apache.activemq.command.ConsumerControl) Session(javax.jms.Session)

Example 10 with ConsumerControl

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

the class AMQConsumer method init.

public void init(SlowConsumerDetectionListener slowConsumerDetectionListener, long nativeId) throws Exception {
    SimpleString selector = info.getSelector() == null ? null : new SimpleString(info.getSelector());
    boolean preAck = false;
    if (info.isNoLocal()) {
        if (!AdvisorySupport.isAdvisoryTopic(openwireDestination)) {
            // tell the connection to add the property
            this.session.getConnection().setNoLocal(true);
        } else {
            preAck = true;
        }
        String id = info.getClientId() != null ? info.getClientId() : this.getId().getConnectionId();
        String noLocalSelector = MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + id + "'";
        if (selector == null) {
            selector = new SimpleString(noLocalSelector);
        } else {
            selector = new SimpleString(info.getSelector() + " AND " + noLocalSelector);
        }
    }
    SimpleString destinationName = new SimpleString(session.convertWildcard(openwireDestination.getPhysicalName()));
    if (openwireDestination.isTopic()) {
        SimpleString queueName = createTopicSubscription(info.isDurable(), info.getClientId(), destinationName.toString(), info.getSubscriptionName(), selector, destinationName);
        serverConsumer = session.getCoreSession().createConsumer(nativeId, queueName, null, info.isBrowser(), false, -1);
        serverConsumer.setlowConsumerDetection(slowConsumerDetectionListener);
        // only advisory topic consumers need this.
        ((ServerConsumerImpl) serverConsumer).setPreAcknowledge(preAck);
    } else {
        try {
            session.getCoreServer().createQueue(destinationName, RoutingType.ANYCAST, destinationName, null, true, false);
        } catch (ActiveMQQueueExistsException e) {
        // ignore
        }
        serverConsumer = session.getCoreSession().createConsumer(nativeId, destinationName, selector, info.isBrowser(), false, -1);
        serverConsumer.setlowConsumerDetection(slowConsumerDetectionListener);
        AddressSettings addrSettings = session.getCoreServer().getAddressSettingsRepository().getMatch(destinationName.toString());
        if (addrSettings != null) {
            // see PolicyEntry
            if (info.getPrefetchSize() != 0 && addrSettings.getQueuePrefetch() == 0) {
                // sends back a ConsumerControl
                ConsumerControl cc = new ConsumerControl();
                cc.setConsumerId(info.getConsumerId());
                cc.setPrefetch(0);
                session.getConnection().dispatch(cc);
            }
        }
    }
    serverConsumer.setProtocolData(this);
}
Also used : ServerConsumerImpl(org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ConsumerControl(org.apache.activemq.command.ConsumerControl) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

ConsumerControl (org.apache.activemq.command.ConsumerControl)20 Session (javax.jms.Session)1 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ServerConsumerImpl (org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1 ExceptionResponse (org.apache.activemq.command.ExceptionResponse)1