Search in sources :

Example 1 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method closeConsumerWithID.

@Override
public boolean closeConsumerWithID(final String sessionID, final String ID) throws Exception {
    checkStarted();
    clearIO();
    try {
        Set<ServerSession> sessions = server.getSessions();
        for (ServerSession session : sessions) {
            if (session.getName().equals(sessionID.toString())) {
                Set<ServerConsumer> serverConsumers = session.getServerConsumers();
                for (ServerConsumer serverConsumer : serverConsumers) {
                    if (serverConsumer.sequentialID() == Long.valueOf(ID)) {
                        serverConsumer.disconnect();
                        return true;
                    }
                }
            }
        }
    } finally {
        blockOnIO();
    }
    return false;
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 2 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method listConsumers.

@Override
public String listConsumers(String options, int page, int pageSize) throws Exception {
    checkStarted();
    clearIO();
    try {
        Set<ServerConsumer> consumers = new HashSet();
        for (ServerSession session : server.getSessions()) {
            consumers.addAll(session.getServerConsumers());
        }
        ConsumerView view = new ConsumerView(server);
        view.setCollection(consumers);
        view.setOptions(options);
        return view.getResultsAsJson(page, pageSize);
    } finally {
        blockOnIO();
    }
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ConsumerView(org.apache.activemq.artemis.core.management.impl.view.ConsumerView) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) HashSet(java.util.HashSet)

Example 3 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class QueueControlImpl method listConsumersAsJSON.

@Override
public String listConsumersAsJSON() throws Exception {
    checkStarted();
    clearIO();
    try {
        Collection<Consumer> consumers = queue.getConsumers();
        JsonArrayBuilder jsonArray = JsonLoader.createArrayBuilder();
        for (Consumer consumer : consumers) {
            if (consumer instanceof ServerConsumer) {
                ServerConsumer serverConsumer = (ServerConsumer) consumer;
                JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("consumerID", serverConsumer.getID()).add("connectionID", serverConsumer.getConnectionID().toString()).add("sessionID", serverConsumer.getSessionID()).add("browseOnly", serverConsumer.isBrowseOnly()).add("creationTime", serverConsumer.getCreationTime());
                jsonArray.add(obj);
            }
        }
        return jsonArray.build().toString();
    } finally {
        blockOnIO();
    }
}
Also used : ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) Consumer(org.apache.activemq.artemis.core.server.Consumer) JsonArrayBuilder(javax.json.JsonArrayBuilder) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 4 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class MQTTSubscriptionManager method stop.

synchronized void stop() throws Exception {
    for (ServerConsumer consumer : consumers.values()) {
        consumer.setStarted(false);
        consumer.disconnect();
        consumer.getQueue().removeConsumer(consumer);
        consumer.close(false);
    }
}
Also used : ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 5 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class StompSession method addSubscription.

public StompPostReceiptFunction addSubscription(long consumerID, String subscriptionID, String clientID, String durableSubscriptionName, String destination, String selector, String ack) throws Exception {
    SimpleString queueName = SimpleString.toSimpleString(destination);
    boolean pubSub = false;
    final int receiveCredits = ack.equals(Stomp.Headers.Subscribe.AckModeValues.AUTO) ? -1 : consumerCredits;
    Set<RoutingType> routingTypes = manager.getServer().getAddressInfo(getCoreSession().removePrefix(SimpleString.toSimpleString(destination))).getRoutingTypes();
    boolean topic = routingTypes.size() == 1 && routingTypes.contains(RoutingType.MULTICAST);
    if (topic) {
        // subscribes to a topic
        pubSub = true;
        if (durableSubscriptionName != null) {
            if (clientID == null) {
                throw BUNDLE.missingClientID();
            }
            queueName = SimpleString.toSimpleString(clientID + "." + durableSubscriptionName);
            if (manager.getServer().locateQueue(queueName) == null) {
                session.createQueue(SimpleString.toSimpleString(destination), queueName, SimpleString.toSimpleString(selector), false, true);
            }
        } else {
            queueName = UUIDGenerator.getInstance().generateSimpleStringUUID();
            session.createQueue(SimpleString.toSimpleString(destination), queueName, SimpleString.toSimpleString(selector), true, false);
        }
    }
    final ServerConsumer consumer = topic ? session.createConsumer(consumerID, queueName, null, false, false, 0) : session.createConsumer(consumerID, queueName, SimpleString.toSimpleString(selector), false, false, 0);
    StompSubscription subscription = new StompSubscription(subscriptionID, ack, queueName, pubSub);
    subscriptions.put(consumerID, subscription);
    session.start();
    return () -> consumer.receiveCredits(receiveCredits);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Aggregations

ServerConsumer (org.apache.activemq.artemis.core.server.ServerConsumer)26 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)7 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)4 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)4 HashSet (java.util.HashSet)3 JsonArrayBuilder (javax.json.JsonArrayBuilder)3 XAException (javax.transaction.xa.XAException)3 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)3 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)3 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)3 ActiveMQXAException (org.apache.activemq.artemis.core.exception.ActiveMQXAException)3 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)3 Test (org.junit.Test)3 JsonObject (javax.json.JsonObject)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2 Binding (org.apache.activemq.artemis.core.postoffice.Binding)2