Untitled
unknown
plain_text
2 years ago
1.5 kB
17
Indexable
If you want to set message priority without using `javax.jms` at all, and you are using Spring's `JmsTemplate`, you can do so by relying on Spring's abstractions. Here's an example using Spring's `MessagePostProcessor`:
```java
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.jms.core.MessagePostProcessor;
public class YourJmsMessageSender {
private JmsTemplate jmsTemplate;
// Injected via setter or constructor injection
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public void sendMessageWithPriority(String destination, String message, int priority) {
jmsTemplate.convertAndSend(destination, message, new MessagePostProcessor() {
@Override
public javax.jms.Message postProcessMessage(javax.jms.Message message) throws javax.jms.JMSException {
message.setJMSPriority(priority);
return message;
}
});
}
}
```
In this example:
- `jmsTemplate.convertAndSend(destination, message, messagePostProcessor)` is used to send a message using Spring's `JmsTemplate`.
- `MessagePostProcessor` is implemented as an anonymous class, allowing you to set the message priority within the `postProcessMessage` method.
This way, you can set the message priority without directly using `javax.jms` interfaces and leveraging Spring's higher-level abstractions.Editor is loading...
Leave a Comment