public String receiveTextMessageFromDestinationWithTimeout ( final String destinationName , final int timeout ) { if ( ! this . isConnected ( ) ) { throw new JmsNotConnectedException ( "Not connected" ) ; } MessageConsumer consumer = getConsumer ( destinationName ) ; TextMessage message ; try { if ( timeout == 0 ) { message = ( TextMessage ) consumer . receiveNoWait ( ) ; } else { message = ( TextMessage ) consumer . receive ( timeout ) ; } if ( message != null ) { if ( acknowledgeMode == Session . CLIENT_ACKNOWLEDGE ) { message . acknowledge ( ) ; } return message . getText ( ) ; } else { return null ; } } catch ( JMSException e ) { throw new JmsException ( "Unable to receive message from " + destinationName , e ) ; } }
Receive a message from destination with timeout .