How check the number of Queue in ReplicationQueue in AEM6.5
Hi All,
I need to check the number of Queues in replicationQueue before proceeding the activate or deactivate in a workflow if the number of queue in replication will be greater than 50 then it shoud not allow to trigger the workflow , how can I approach this?
@Override
public void execute (WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
String payload = workItem.getWorkflowData().getPayload().toString();
if (rootPage != null && replicationQueueChechk()) {
if (StringUtils.equalsIgnoreCase(comments, MOVE_TO_DEV_UNPUBLISH)) {
replicationOptions.setFilter(agent -> agent.getId().matches(".*(?<!agent)$"));
}
if (StringUtils.equalsIgnoreCase(comments, MOVE_TO_QA_UNPUBLISH)) {
replicationOptions.setFilter(agent -> agent.getId().endsWith("agent"));
}
try {
replicator.replicate(session, ReplicationActionType.DEACTIVATE, payload, replicationOptions);
} catch (ReplicationException e) {
loggerService.postLog(LogLevel.ERROR, "Replication exception occurred at :: {}" + Arrays.toString(paths) + " and the error message is :: {}" + e.getMessage());
}
}
}
private boolean replicationQueueChechk () {
//TODO check the number of active objects in replication queue, return true only if replication queue is less than 500, otherwise return false
}
I tried to follow multiple documents like : https://javadoc.io/static/com.adobe.aem/aem-sdk-api/2023.4.11873.20230421T153841Z-230200/com/day/cq/replication/ReplicationQueue.Entry.html#getQueue()
But could not able to acieve this.
Could you please guide me the approach.
tried solution :
//Get the replication queue from the session object
//Get the entries list from the replication queue.
//Get the size of the entries, and then de-activate based on it.
private boolean replicationQueueChechk (Session session) {
ReplicationQueue replicationQueue = Replication.getQueue(resourceResolver.adaptTo(session.class)); List<ReplicationQueueEntry> queueEntries = replicationQueue.entries();
if (queueEntries.size() < 500) {
// If yes, then deactivate the pages
} else {
//some message
}
}or
private boolean replicationQueueCheck() {
ReplicationQueue replicationQueue = session.adaptTo(ReplicationQueue.class);
int queueSize = replicationQueue != null ? replicationQueue.getQueueEntries().size() : 0;
return queueSize < 500;
}
private boolean isReplicationQueueUnderLimit(int limit) {
ReplicationQueue replicationQueue = session.adaptTo(ReplicationQueue.class);
int queueSize = replicationQueue != null ? replicationQueue.getQueueEntries().size() : 0;
return queueSize < limit;
}or
public int getQueueCount(ResourceResolver resourceResolver, String agentId) throws SlingException {
ReplicationAgentManager agentManager = resourceResolver.adaptTo(ReplicationAgentManager.class);
ReplicationQueue replicationQueue = agentManager.getQueue(agentId);
if (replicationQueue != null) {
java.util.List<QueueEntry> queueEntries = replicationQueue.getQueueEntries();
return queueEntries.size();
}
return 0;
}
Thanks