rabbitmq消费数据读取header中的值

protected String extractCorrelationIdFromHeaders(AMQP.BasicProperties properties) throws UnsupportedEncodingException {

    String decodedCorrelationId=null;

    if(properties.getHeaders() != null) {

        try {
            Object rawCorrelationId = properties.getHeaders().get(CORRELATION_ID_KEY);

            if(rawCorrelationId==null){
                log.info("no correlationId provided in headers");
                return null;
            }

            byte[] correlationIdAsByteArray = ((LongString) rawCorrelationId).getBytes();

            decodedCorrelationId = new String(correlationIdAsByteArray, "UTF-8");
        }
        catch(UnsupportedEncodingException e){
            log.warn("extracted correlationId, but unable to decode it",e);
        }
    }

    return decodedCorrelationId;
}

 

你可能感兴趣的:(bootstrap)