本文整理匯總了Java中javax.jms.TextMessage.getPropertyNames方法的典型用法代碼示例。如果您正苦於以下問題:Java TextMessage.getPropertyNames方法的具體用法?Java TextMessage.getPropertyNames怎麽用?Java TextMessage.getPropertyNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TextMessage
的用法示例。
在下文中一共展示了TextMessage.getPropertyNames方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMessageHeaders
import javax.jms.TextMessage; //導入方法依賴的package包/類
private Map<String, String> getMessageHeaders(TextMessage message) throws JMSException {
Map<String, String> map = new HashMap<>();
Enumeration<String> names = message.getPropertyNames();
while (names.hasMoreElements()) {
String key = names.nextElement();
map.put(key, message.getStringProperty(key));
}
return map;
}
示例2: readJmsMessage
import javax.jms.TextMessage; //導入方法依賴的package包/類
@Override
public Optional<EventMessage<?>> readJmsMessage(Message msg) throws JMSException {
if (!(msg instanceof TextMessage)) {
return Optional.empty();
}
final TextMessage textMsg = (TextMessage) msg;
if (textMsg.getObjectProperty("axon-message-id") == null
|| textMsg.getObjectProperty("axon-message-type") == null) {
return Optional.empty();
}
Map<String, Object> metaData = new HashMap<>();
Enumeration<String> propertyNames = textMsg.getPropertyNames();
while (propertyNames.hasMoreElements()) {
String propertyName = propertyNames.nextElement();
if (propertyName.startsWith("axon-metadata-")) {
metaData.put(propertyName.substring("axon-metadata-".length()),
textMsg.getObjectProperty(propertyName));
}
}
SimpleSerializedObject<String> serializedObject = new SimpleSerializedObject<>(
textMsg.getText(), String.class,
textMsg.getStringProperty("axon-message-type"),
textMsg.getStringProperty("axon-message-revision"));
SerializedMessage<EventMessage<?>> serializedMessage = new SerializedMessage<>(
textMsg.getStringProperty("axon-message-id"),
new LazyDeserializingObject<>(serializedObject, serializer),
new LazyDeserializingObject<>(MetaData.from(metaData)));
String timestamp = textMsg.getStringProperty("axon-message-timestamp");
if (textMsg.propertyExists("axon-message-aggregate-id")) {
return Optional.of(new GenericDomainEventMessage<>(
textMsg.getStringProperty("axon-message-aggregate-type"),
textMsg.getStringProperty("axon-message-aggregate-id"),
textMsg.getLongProperty("axon-message-aggregate-seq"),
serializedMessage,
() -> Instant.parse(timestamp)));
} else {
return Optional.of(new GenericEventMessage<>(
serializedMessage, () -> Instant.parse(timestamp)));
}
}