I have a problem with functionality which is not implemented in all offered programming languages. The use case i work on is a utility to move messages from DMQ back to main queue to re-publish the messages).
The problem is that there is a flag DMQ eligible
So i want to do following:
- Subscribe on DMQ
- Take messages 1:1 with just change back to DMQ-eligible = true
(that is needed as in DMQ it turns - not sure why to false)
These problems are already discussed in this thread:
Moving messages from deadletter queue to main queue in Solace — Solace Community - Problem is now that message read can not be changed as set to read only
and you can not change.
And copy is only possible in C:
PubSub+ Messaging API Developer Guide
What i have done now is to do following and i wonder if there is a better way:
private Message cloneMessage(Message message) {
try {
HashMap<String, Object> propertyMap = new HashMap<>();
Enumeration propertyNames = message.getPropertyNames();
// Read all properties and read in Hashmap
while (propertyNames.hasMoreElements()) {
String property = propertyNames.nextElement().toString();
Object propertyObject = message.getObjectProperty(property);
propertyMap.put(property,propertyObject);
}
// Clear any properties from source message
Iterator propertyIterator = propertyMap.entrySet().iterator();
message.clearProperties();
while (propertyIterator.hasNext()) {
Map.Entry propertyElement = (Map.Entry)propertyIterator.next();
message.setObjectProperty(propertyElement.getKey().toString(),propertyElement.getValue());
}
} catch (Exception e) {
System.out.println(“Error cloning message.”);
e.printStackTrace();
}
return message;
}