Untitled
unknown
plain_text
a year ago
1.5 kB
2
Indexable
Never
If you're looking to set message priority without using `javax.jms` directly, you can use Spring's `JmsTemplate` along with a `MessageConverter`. Here's an example using Spring's `JmsTemplate`: ```java import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessageCreator; 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.send(destination, new MessageCreator() { @Override public javax.jms.Message createMessage(javax.jms.Session session) throws javax.jms.JMSException { javax.jms.Message jmsMessage = session.createTextMessage(message); jmsMessage.setJMSPriority(priority); return jmsMessage; } }); } } ``` In this example: - `jmsTemplate.send(destination, messageCreator)` is used to send a message using Spring's `JmsTemplate`. - `MessageCreator` is implemented as an anonymous class, allowing you to set the message priority within the `createMessage` method. Ensure that you have the necessary Spring dependencies configured in your project, and that the `JmsTemplate` bean is properly set up with the connection factory. This way, you can set the message priority without directly using `javax.jms` interfaces.
Leave a Comment