use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.
the class ServerSessionImpl method setStarted.
private void setStarted(final boolean s) {
Set<ServerConsumer> consumersClone = new HashSet<>(consumers.values());
for (ServerConsumer consumer : consumersClone) {
consumer.setStarted(s);
}
started = s;
}
use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.
the class ServerSessionImpl method createConsumer.
@Override
public ServerConsumer createConsumer(final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception {
final SimpleString unPrefixedQueueName = removePrefix(queueName);
Binding binding = postOffice.getBinding(unPrefixedQueueName);
if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(unPrefixedQueueName);
}
SimpleString address = removePrefix(binding.getAddress());
if (browseOnly) {
try {
securityCheck(address, queueName, CheckType.BROWSE, this);
} catch (Exception e) {
securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.BROWSE, this);
}
} else {
try {
securityCheck(address, queueName, CheckType.CONSUME, this);
} catch (Exception e) {
securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.CONSUME, this);
}
}
Filter filter = FilterImpl.createFilter(filterString);
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeCreateConsumer(consumerID, (QueueBinding) binding, filterString, browseOnly, supportLargeMessage));
}
ServerConsumer consumer = new ServerConsumerImpl(consumerID, this, (QueueBinding) binding, filter, started, browseOnly, storageManager, callback, preAcknowledge, strictUpdateDeliveryCount, managementService, supportLargeMessage, credits, server);
consumers.put(consumer.getID(), consumer);
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterCreateConsumer(consumer));
}
if (!browseOnly) {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
Queue theQueue = (Queue) binding.getBindable();
props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());
// HORNETQ-946
props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));
props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));
props.putSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));
if (filterString != null) {
props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
}
Notification notification = new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);
if (logger.isDebugEnabled()) {
logger.debug("Session with user=" + username + ", connection=" + this.remotingConnection + " created a consumer on queue " + unPrefixedQueueName + ", filter = " + filterString);
}
managementService.sendNotification(notification);
}
return consumer;
}
use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.
the class ServerSessionImpl method acknowledge.
@Override
public void acknowledge(final long consumerID, final long messageID) throws Exception {
ServerConsumer consumer = findConsumer(consumerID);
if (tx != null && tx.getState() == State.ROLLEDBACK) {
// JBPAPP-8845 - if we let stuff to be acked on a rolled back TX, we will just
// have these messages to be stuck on the limbo until the server is restarted
// The tx has already timed out, so we need to ack and rollback immediately
Transaction newTX = newTransaction();
try {
consumer.acknowledge(newTX, messageID);
} catch (Exception e) {
// just ignored
// will log it just in case
logger.debug("Ignored exception while acking messageID " + messageID + " on a rolledback TX", e);
}
newTX.rollback();
} else {
consumer.acknowledge(autoCommitAcks ? null : tx, messageID);
}
}
use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testCloseCOREclient.
@Test
public void testCloseCOREclient() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString name = RandomUtil.randomSimpleString();
boolean durable = true;
ActiveMQServerControl serverControl = createManagementControl();
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
serverControl.createAddress(address.toString(), "ANYCAST");
serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), null, durable, -1, false, false);
ServerLocator receiveLocator = createInVMNonHALocator();
ClientSessionFactory receiveCsf = createSessionFactory(receiveLocator);
ClientSession receiveClientSession = receiveCsf.createSession(true, false, false);
final ClientConsumer COREclient = receiveClientSession.createConsumer(name);
ServerSession ss = server.getSessions().iterator().next();
ServerConsumer sc = ss.getServerConsumers().iterator().next();
Assert.assertFalse(COREclient.isClosed());
serverControl.closeConsumerWithID(((ClientSessionImpl) receiveClientSession).getName(), Long.toString(sc.sequentialID()));
Wait.waitFor(() -> COREclient.isClosed());
Assert.assertTrue(COREclient.isClosed());
}
use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.
the class AMQPSessionCallback method closeSender.
public void closeSender(final Object brokerConsumer) throws Exception {
final ServerConsumer consumer = ((ServerConsumer) brokerConsumer);
final CountDownLatch latch = new CountDownLatch(1);
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
consumer.close(false);
latch.countDown();
} catch (Exception e) {
}
}
};
// Due to the nature of proton this could be happening within flushes from the queue-delivery (depending on how it happened on the protocol)
// to avoid deadlocks the close has to be done outside of the main thread on an executor
// otherwise you could get a deadlock
Executor executor = protonSPI.getExeuctor();
if (executor != null) {
executor.execute(runnable);
} else {
runnable.run();
}
try {
// a short timeout will do.. 1 second is already long enough
if (!latch.await(1, TimeUnit.SECONDS)) {
logger.debug("Could not close consumer on time");
}
} catch (InterruptedException e) {
throw new ActiveMQAMQPInternalErrorException("Unable to close consumers for queue: " + consumer.getQueue());
}
consumer.getQueue().recheckRefCount(serverSession.getSessionContext());
}
Aggregations