[rabbitmq-discuss] How to check if custom headers attribute exist

Tim Watson tim at rabbitmq.com
Thu Jan 30 16:58:49 GMT 2014


BasicProperties#getHeaders() returns a Map, so Map#get(key) will return `null' if the key isn't present. It's your #toString() on `null' that is likely causing the problem. You could also call Map#containsKey("FirstName") instead of checking for `null' if you prefer.

Cheers,
Tim

On 30 Jan 2014, at 16:30, cw storm wrote:

> Please forgive me but I have a simple question.  How can I check to see if there's custom header attribute exist or not before I perform the below:
> 
> String strFirstName = props.getHeaders().get("FirstName").toString()
> 
> I believe if there's no custom headers, then it'll exception.
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss



More information about the rabbitmq-discuss mailing list