2

I'm listening to MQ Q's using Spring JMS @JmsListener annotation.

    @JmsListener(destination = "${qNmae}", 
                    containerFactory = "jmsListenerContainerFactory2")
    public void processMessage(Message<String> msg) throws JMSException {

    }

I need to convert Spring Message object into New JMS TextMessage. I know I can put the method parameter of type TextMessage instead of Message and the Spring automatically converts it but then I'm getting immutable object but my code requires me to keep existing headers and add new headers in certain cases. Basically I'm looking for proper way to duplicate the JMS Message/TextMessage object so that I can add my own headers without the JMS Session objects(As I'm using @JmsListener, I don't want to create new sessions myself just for creating new message).

risingTide
  • 1,754
  • 7
  • 31
  • 60
user3817206
  • 315
  • 4
  • 14

1 Answers1

1

In this case you can create a new instance of the Message and copy headers or add a session as a parameter to your method processMessage and spring will inject the session you can use to create a new Message ( depends on implementation but i think session will only create a new instance like first proposal ) and copy headers

Hassen Bennour
  • 3,885
  • 2
  • 12
  • 20