本文整理汇总了Java中javax.jms.Message.getJMSCorrelationID方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getJMSCorrelationID方法的具体用法?Java Message.getJMSCorrelationID怎么用?Java Message.getJMSCorrelationID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.Message
的用法示例。
在下文中一共展示了Message.getJMSCorrelationID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import javax.jms.Message; //导入方法依赖的package包/类
private void handleMessage(MessageHandler handler, Message message, Session session) {
if (! (message instanceof TextMessage)) {
return;
}
TextMessage textMessage = (TextMessage) message;
String text = null;
String requestId = UUID.randomUUID().toString();
try {
text = textMessage.getText();
if (StringUtils.isNotEmpty(message.getJMSCorrelationID())) {
requestId = message.getJMSCorrelationID();
}
MDC.put(X_OBOS_REQUEST_ID, requestId);
log.info("Received message '{}'", text);
handler.handle(new ObjectMapper().readTree(text));
} catch (Exception e) {
log.error("Failed to process message", e);
try {
TextMessage errorMessage = session.createTextMessage(text);
errorMessage.setJMSCorrelationID(requestId);
Queue queue = session.createQueue(queueError);
MessageProducer errorProducer = session.createProducer(queue);
errorProducer.send(errorMessage);
} catch (JMSException jmse) {
log.error("Failed to create error message", jmse);
}
} finally {
MDC.remove(X_OBOS_REQUEST_ID);
}
}
示例2: isValidRequestResponse
import javax.jms.Message; //导入方法依赖的package包/类
/**
* Since we use a request/response communication style with the client,
* we must ensure that tha appropriate fields are set.
*/
private boolean isValidRequestResponse(Message incoming) {
try {
if (incoming.getJMSCorrelationID() == null) {
getLogger().warn("JMSCorrelationID is not set! Will not process request");
return false;
}
if (incoming.getJMSReplyTo() == null) {
getLogger().warn("JMSReplyTo is not set! Will not process request");
return false;
}
} catch (JMSException e) {
getLogger().warn(
"Failed to read JMSCorrelationID/JMSReplyTo. " +
"Will not process request. Exception message = {}", e.getMessage());
return false;
}
return true;
}