Search in sources :

Example 1 with ConsumerTemplate

use of com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessagingController method getEntityRequests.

@RequestMapping(value = "/api/v1/data-nodes/entities", method = GET)
public List<CommonEntityRequestDTO> getEntityRequests(Principal principal) throws PermissionDeniedException, JMSException {
    DataNode dataNode = getDatanode(principal);
    final String requestQueue = getRequestQueueName(MessagingUtils.Entities.getBaseQueue(dataNode));
    ConsumerTemplate consumerTpl = new ConsumerTemplate(destinationResolver, requestQueue, // Give some time for case when new connection to a broker is established
    1000L);
    List<CommonEntityRequestDTO> cohortRequests = new ArrayList<>();
    while (true) {
        ObjectMessage requestMessage = jmsTemplate.execute(consumerTpl, true);
        if (requestMessage == null) {
            break;
        }
        final CommonEntityRequestDTO cohortRequest = (CommonEntityRequestDTO) requestMessage.getObject();
        cohortRequest.setId(requestMessage.getJMSCorrelationID());
        cohortRequests.add(cohortRequest);
    }
    return cohortRequests;
}
Also used : ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) DataNode(com.odysseusinc.arachne.portal.model.DataNode) ObjectMessage(javax.jms.ObjectMessage) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ConsumerTemplate

use of com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessageServiceImpl method getListRequest.

@Override
public CommonListEntityRequest getListRequest(DN dataNode) throws JMSException {
    Map<String, CommonEntityRequestObject> requestMap = new LinkedHashMap<>();
    String requestQueue = getRequestQueueName(MessagingUtils.EntitiesList.getBaseQueue(dataNode));
    ConsumerTemplate consumerTpl = new ConsumerTemplate(destinationResolver, requestQueue, // Give some time for case when new connection to a broker is established
    1000L);
    while (true) {
        ObjectMessage requestMessage = jmsTemplate.execute(consumerTpl, true);
        if (requestMessage == null) {
            break;
        }
        requestMap.put(requestMessage.getJMSCorrelationID(), (CommonEntityRequestObject) requestMessage.getObject());
    }
    return new CommonListEntityRequest(requestMap);
}
Also used : ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) ObjectMessage(javax.jms.ObjectMessage) CommonListEntityRequest(com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate)2 ObjectMessage (javax.jms.ObjectMessage)2 CommonEntityRequestDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO)1 CommonEntityRequestObject (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject)1 CommonListEntityRequest (com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest)1 ProducerConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate)1 DataNode (com.odysseusinc.arachne.portal.model.DataNode)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1