6
是否有將屬性從一個JMS消息複製到另一個的簡單方法?複製JMS消息屬性
我能想象這樣的事情:
private void copyMessageProperties (Message msg1, Message msg2) throws JMSException {
Enumeration srcProperties = msg1.getPropertyNames();
while (srcProperties.hasMoreElements()) {
String propertyName = (String) srcProperties.nextElement();
// Now try to read and set
try {
Object obj = msg1.getObjectProperty (propertyName);
msg2.setObjectProperty (propertyName, obj);
continue;
} catch (Exception e) {}
try {
String str = msg1.getStringProperty (propertyName);
msg2.setStringProperty (propertyName, str);
continue;
...
}
}
}
但是,這是嚴重的醜陋。必須有另一種方式
LinkedHashMap中是更好地維護秩序 – mcoolive 2015-12-14 02:10:57