mail@pastecode.io avatar
8 days ago
1.5 kB
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`:

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() {
            public javax.jms.Message createMessage(javax.jms.Session session) throws javax.jms.JMSException {
                javax.jms.Message jmsMessage = session.createTextMessage(message);
                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