use of javax.jms.ObjectMessage in project rocketmq-externals by apache.
the class MessageConverter method getContentFromJms.
public static byte[] getContentFromJms(javax.jms.Message jmsMessage) throws Exception {
byte[] content;
if (jmsMessage instanceof TextMessage) {
if (StringUtils.isEmpty(((TextMessage) jmsMessage).getText())) {
throw new IllegalArgumentException("Message body length is zero");
}
content = MsgConvertUtil.string2Bytes(((TextMessage) jmsMessage).getText(), Charsets.UTF_8.toString());
} else if (jmsMessage instanceof ObjectMessage) {
if (((ObjectMessage) jmsMessage).getObject() == null) {
throw new IllegalArgumentException("Message body length is zero");
}
content = MsgConvertUtil.objectSerialize(((ObjectMessage) jmsMessage).getObject());
} else if (jmsMessage instanceof BytesMessage) {
JmsBytesMessage bytesMessage = (JmsBytesMessage) jmsMessage;
if (bytesMessage.getBodyLength() == 0) {
throw new IllegalArgumentException("Message body length is zero");
}
content = bytesMessage.getData();
} else {
throw new IllegalArgumentException("Unknown message type " + jmsMessage.getJMSType());
}
return content;
}
use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.
the class BaseDataNodeMessageServiceImpl method getDataList.
@Override
@PreAuthorize("hasPermission(#dataNode, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).IMPORT_FROM_DATANODE)")
public <T extends CommonEntityDTO> List<T> getDataList(DN dataNode, CommonAnalysisType analysisType) throws JMSException {
Long waitForResponse = messagingTimeout;
Long messageLifeTime = messagingTimeout;
// Get all Atlases available in user's tenant
List<IAtlas> atlasList = atlasService.findAll().stream().filter(a -> a.getVersion() != null).collect(Collectors.toList());
String baseQueue = MessagingUtils.EntitiesList.getBaseQueue(dataNode);
ProducerConsumerTemplate exchangeTpl = new ProducerConsumerTemplate(destinationResolver, new CommonEntityRequestObject(atlasList.stream().map(IAtlas::getId).collect(Collectors.toList()), analysisType), baseQueue, waitForResponse, messageLifeTime);
ObjectMessage responseMessage = jmsTemplate.execute(exchangeTpl, true);
List<T> entityList = (List<T>) responseMessage.getObject();
Map<Long, IAtlas> atlasMap = atlasList.stream().collect(Collectors.toMap(IAtlas::getId, a -> a));
entityList.forEach(e -> e.setName(atlasMap.get(e.getOriginId()).getName() + ": " + e.getName()));
return entityList;
}
use of javax.jms.ObjectMessage 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);
}
use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method getEntityFiles.
public List<MultipartFile> getEntityFiles(DataReferenceDTO entityReference, DataNode dataNode, CommonAnalysisType entityType) throws JMSException, IOException, URISyntaxException {
Long waitForResponse = datanodeImportTimeout;
Long messageLifeTime = datanodeImportTimeout;
String baseQueue = MessagingUtils.Entities.getBaseQueue(dataNode);
CommonEntityRequestDTO request = new CommonEntityRequestDTO(entityReference.getEntityGuid(), entityType);
ProducerConsumerTemplate exchangeTpl = new ProducerConsumerTemplate(destinationResolver, request, baseQueue, waitForResponse, messageLifeTime);
final ObjectMessage responseMessage = jmsTemplate.execute(exchangeTpl, true);
if (responseMessage == null) {
String message = String.format(ENTITY_IS_NOT_AVAILABLE, entityType.getTitle(), entityReference.getEntityGuid(), entityReference.getDataNodeId());
throw new ServiceNotAvailableException(message);
}
final List<ImportedFile> importedFiles = (List<ImportedFile>) responseMessage.getObject();
boolean hasAnalysisRunner = hasAnalysisRunner(importedFiles);
if (entityType.equals(CommonAnalysisType.ESTIMATION) && !hasAnalysisRunner) {
return importService.processEstimation(importedFiles);
}
List<MultipartFile> files = importedFiles.stream().map(file -> conversionService.convert(file, MockMultipartFile.class)).collect(Collectors.toList());
if (!hasAnalysisRunner) {
files.addAll(generateAnalysisFiles(entityType));
}
return files;
}
use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.
the class BaseDataNodeMessagingController method getEntityRequests.
@ApiOperation("List all EntityRequests")
@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;
}
Aggregations