private void purgeDestination ( Destination destination , Session session , String destinationName ) throws JMSException { if ( log . isDebugEnabled ( ) ) { log . debug ( "Try to purge destination " + destinationName ) ; } int messagesPurged = 0 ; MessageConsumer messageConsumer = session . createConsumer ( destination ) ; try { javax . jms . Message message ; do { message = ( receiveTimeout >= 0 ) ? messageConsumer . receive ( receiveTimeout ) : messageConsumer . receive ( ) ; if ( message != null ) { log . debug ( "Removed message from destination " + destinationName ) ; messagesPurged ++ ; try { Thread . sleep ( sleepTime ) ; } catch ( InterruptedException e ) { log . warn ( "Interrupted during wait" , e ) ; } } } while ( message != null ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Purged " + messagesPurged + " messages from destination" ) ; } } finally { JmsUtils . closeMessageConsumer ( messageConsumer ) ; } }
Purge destination by receiving all available messages .