简体   繁体   中英

org.springframework.messaging.converter.MessageConversionException: Cannot convert from [org.apache.qpid.jms.message.JmsMessage] to [java.lang.String]

    Reading message from Azure service bus:
    org.springframework.messaging.converter.MessageConversionException: Cannot convert from [org.apache.qpid.jms.message.JmsMessage] to [java.lang.String] for org.springframework.jms.listener.adapter.AbstractAdaptableMessageListener$MessagingMessageConverterAdapter$LazyResolutionMessage@39945b52, failedMessage=org.springframework.jms.listener.adapter.AbstractAdaptableMessageListener$MessagingMessageConverterAdapter$LazyResolutionMessage@39945b52
    
    java code:

import org.apache.qpid.jms.message.JmsMessage;

@Component Public class AzureserviceBusListner { private final static String QUEUE_NAME = "teste01";

@JmsListener(destination = QUEUE_NAME,containerFactory = "jmsListenerContainerFactory")

    public void receive(String msg) {

      System.out.println("Azure received message:::: "+msg);    

   }
}

You can send a JmsTextMessage iinstead of a JmsMessage:

        //Autowire a JmsTemplate first, and then

        jmsTemplate.send("<your-destination-name>", new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            TextMessagemessage = session.createTextMessage("message payload");

            return message;
        }
    });

I am curious of what's is the need here to send a JmsMessage instead of sub class? I think you can also use message converter to convert the JmsMessage to sub classes as you need when sending/receiving messages.

Besides, do you use the azure-spring-boot-starter-servicebus-jms If so, converting JmsMessage to other JAVA type in message converter will not work because that library doesn't support customize messageconverter for JmsListener.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM