Search in sources :

Example 1 with RetryMessage

use of org.orcid.utils.listener.RetryMessage in project ORCID-Source by ORCID.

the class RetryListener method processMessage.

/**
 * Processes messages on receipt.
 *
 * @param map
 * @throws JsonProcessingException
 * @throws JAXBException
 * @throws AmazonClientException
 */
@JmsListener(destination = MessageConstants.Queues.RETRY)
public void processMessage(final Map<String, String> map) throws JsonProcessingException, AmazonClientException, JAXBException {
    RetryMessage message = new RetryMessage(map);
    String orcid = message.getOrcid();
    if (message.getMap() == null || message.getMap().get(RetryMessage.BROKER_NAME) == null) {
        throw new MissingResourceException("Unable to find destination broker", String.class.getName(), RetryMessage.BROKER_NAME);
    }
    AvailableBroker destinationBroker = AvailableBroker.fromValue(message.getMap().get(RetryMessage.BROKER_NAME));
    LOG.info("Recieved " + MessageConstants.Queues.RETRY + " message for orcid " + orcid + " to broker " + destinationBroker);
    if (AvailableBroker.DUMP_STATUS_1_2_API.equals(destinationBroker) || AvailableBroker.DUMP_STATUS_2_0_API.equals(destinationBroker)) {
        s3Processor.accept(message);
    } else if (AvailableBroker.SOLR.equals(destinationBroker)) {
        solrProcessor.accept(message);
    }
}
Also used : AvailableBroker(org.orcid.listener.persistence.util.AvailableBroker) MissingResourceException(java.util.MissingResourceException) RetryMessage(org.orcid.utils.listener.RetryMessage) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 2 with RetryMessage

use of org.orcid.utils.listener.RetryMessage in project ORCID-Source by ORCID.

the class HandleFailedMessages method resendFailedElements.

@Scheduled(cron = "${org.orcid.cron.reindex-failed}")
public void resendFailedElements() {
    List<RecordStatusEntity> failedElements = manager.getFailedElements(BATCH_SIZE);
    List<RecordStatusEntity> elementsToNotify = new ArrayList<RecordStatusEntity>();
    for (RecordStatusEntity element : failedElements) {
        try {
            // Send RetryMessage for 1.2 dump
            if (element.getDumpStatus12Api() > 0) {
                RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_1_2_API.value());
                jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
            }
            // Send RetryMessage for 2.0 dump
            if (element.getDumpStatus20Api() > 0) {
                RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_2_0_API.value());
                jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
            }
            // Send RetryMessage for solr indexing
            if (element.getSolrStatus20Api() > 0) {
                RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.SOLR.value());
                jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
            }
            // Send RetryMessage for 2.0 activities dump
            if (element.getDumpStatus20ActivitiesApi() > 0) {
                RetryMessage message = new RetryMessage(element.getId(), AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API.value());
                jmsTemplate.convertAndSend(MessageConstants.Queues.RETRY, message.getMap());
            }
            // Should we notify about this element?
            if ((element.getDumpStatus12Api() > maxFailuresBeforeNotify) || (element.getDumpStatus20Api() > maxFailuresBeforeNotify) || (element.getSolrStatus20Api() > maxFailuresBeforeNotify) || (element.getDumpStatus20ActivitiesApi() > maxFailuresBeforeNotify)) {
                elementsToNotify.add(element);
            }
        } catch (JmsException e) {
            LOGGER.warn("Unable to resend message for " + element.getId());
        }
    }
    // Send summary
    if (!elementsToNotify.isEmpty()) {
        String message = buildNotificationMessage(elementsToNotify);
        sendSystemAlert(message);
    }
}
Also used : RecordStatusEntity(org.orcid.listener.persistence.entities.RecordStatusEntity) JmsException(org.springframework.jms.JmsException) ArrayList(java.util.ArrayList) RetryMessage(org.orcid.utils.listener.RetryMessage) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

RetryMessage (org.orcid.utils.listener.RetryMessage)2 ArrayList (java.util.ArrayList)1 MissingResourceException (java.util.MissingResourceException)1 RecordStatusEntity (org.orcid.listener.persistence.entities.RecordStatusEntity)1 AvailableBroker (org.orcid.listener.persistence.util.AvailableBroker)1 JmsException (org.springframework.jms.JmsException)1 JmsListener (org.springframework.jms.annotation.JmsListener)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1