public void listenTextMessagesWithDestination ( final String destinationName , final Consumer < String > messageListener ) { final MessageConsumer consumer = getConsumer ( destinationName ) ; try { consumer . setMessageListener ( message -> { try { messageListener . accept ( ( ( TextMessage ) message ) . getText ( ) ) ; if ( acknowledgeMode == Session . CLIENT_ACKNOWLEDGE ) { message . acknowledge ( ) ; } } catch ( JMSException e ) { throw new JmsException ( "Unable to register get text from message in listener " + destinationName , e ) ; } catch ( Exception ex ) { throw new IllegalStateException ( "Unable handle JMS Consumer " + destinationName , ex ) ; } } ) ; } catch ( JMSException e ) { throw new JmsException ( "Unable to register message listener " + destinationName , e ) ; } }
Listen to a message from JMS from a given destination by name .