Spring JMSListener - How should it handle empty payloads?
<p>I asked basically the same thing a few months ago with this post: <a href="https://stackoverflow.com/questions/36518678/how-should-a-spring-jms-listener-handle-a-message-with-an-empty-payload">How should a Spring JMS listener handle a message with an empty payload?</a>, but all I got was a measly comment suggesting I "re-write my listener to do what I want". Valid statement, but unclear in my eyes as I'm still coming to grips with Spring-Boot. I've learned since then and want to re-ask this question more directly (as opposed to placing a bounty on the old one).</p>

<p>I set up an annotated bean class with <code>@Configuration</code> and <code>@EnableJms</code> and my container factory looks like:</p>

<pre><code>@Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(mqConnectionFactory());
        factory.setDestinationResolver(destinationResolver());
        factory.setConcurrency("1");
        factory.setErrorHandler(errorHandler());
        factory.setSessionTransacted(true);
        factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
        return factory;
    }
</code></pre>

<p>And the listener looks like: </p>

<pre><code>@JmsListener(id = "qID", destination = "qName")
    public void processOrder(String message) {. . .}
</code></pre>

<p>As I understand it, once the annotated bean class gets ran through, the <code>JMSListener</code> basically kicks off (unless I set <code>autoStartup</code> to false), so I fail to understand where and when I have control over what or how the <code>JmsListener</code> handles things. From my perspective it "just runs". So if a queue has <code>"\n"</code> on it or just an empty string, the listener is going to throw an exception. Specifically <code>org.springframework.messaging.converter.MessageConversionException: No converter found to convert to class java.lang.String</code>. And this exception is thrown behind the scenes. I <strong>never get the chance to execute anything inside the listener</strong></p>

<p>I looked into <code>SimpleMessageConverter</code> but didn't seem to see anything that would allow me to say something like <code>setIgnoreStringPattern()</code>. That obviously doesn't exist, but that's what I need. What am I missing? Is there a way to tell the <code>JmsListener</code> to ignore certain strings?</p>