public static String getMd5Hash ( String topic , String [ ] partitions ) { ArrayList < String > elements = new ArrayList < String > ( ) ; elements . add ( topic ) ; for ( String partition : partitions ) { elements . add ( partition ) ; } String pathPrefix = StringUtils . join ( elements , "/" ) ; try { final MessageDigest messageDigest = MessageDigest . getInstance ( "MD5" ) ; byte [ ] md5Bytes = messageDigest . digest ( pathPrefix . getBytes ( "UTF-8" ) ) ; return getHexEncode ( md5Bytes ) . substring ( 0 , 4 ) ; } catch ( NoSuchAlgorithmException e ) { LOG . error ( e . getMessage ( ) ) ; } catch ( UnsupportedEncodingException e ) { LOG . error ( e . getMessage ( ) ) ; } return "" ; }
Generate MD5 hash of topic and partitions . And extract first 4 characters of the MD5 hash .