本文整理汇总了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)));
}
}