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;
}
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();
}
}
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();
}
}
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);
}
}
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);
}
Aggregations