I'm trying to add a header x-delay on my messages using a instance of MessagePostProcessor but it gives me an exception saying:
java.lang.UnsupportedOperationException: MessageHeaders is immutable
import org.springframework.messaging.Message
import org.springframework.messaging.core.MessagePostProcessor
import org.springframework.stereotype.Component
@Component
class AmpqRoutingKeyStrategy {
private static CUSTOM_DELAY = 120000
MessagePostProcessor get() {
return withDelay(CUSTOM_DELAY)
}
static MessagePostProcessor withDelay(Integer milliSeconds) {
return new MessagePostProcessor() {
@Override
Message postProcessMessage(Message message) {
message.getHeaders().put('x-delay', milliSeconds)
return message
}
}
}
}
The example above is used in many articles about this topic, I know that we have the option to add the x-delay header but how can I do it without raising this exception?