[rabbitmq-discuss] How to check if custom headers attribute exist
cw storm
cwstorm at gmail.com
Thu Jan 30 18:24:38 GMT 2014
Nevermind. I was able to get around my issue. During publish, I should
not populate the key. That way, during consumption, I can use the method
"containsKey" properly. Thanks.
-PH
On Thu, Jan 30, 2014 at 12:38 PM, cw storm <cwstorm at gmail.com> wrote:
> Can I do a check something like below?
>
> if (headers.getHeaders().get("FirstName") != null))
>
>
> On Thu, Jan 30, 2014 at 12:35 PM, cw storm <cwstorm at gmail.com> wrote:
>
>> Actually, I need to check if "FirstName" is null or not in order to use
>> toString().
>>
>>
>> On Thu, Jan 30, 2014 at 12:26 PM, cw storm <cwstorm at gmail.com> wrote:
>>
>>> Does this look right?
>>>
>>> Map<String,object> headers = properties.getHeaders();
>>>
>>> if (headers.containsKey("FirstName")) {
>>> String strFirstName = props.getHeaders().get("
>>> FirstName").toString();
>>> }
>>>
>>>
>>>
>>> On Thu, Jan 30, 2014 at 12:18 PM, cw storm <cwstorm at gmail.com> wrote:
>>>
>>>> Thanks Tim. How do code to see if the key is there or not?
>>>>
>>>>
>>>> On Thu, Jan 30, 2014 at 11:58 AM, Tim Watson <tim at rabbitmq.com> wrote:
>>>>
>>>>> 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
>>>>>
>>>>> _______________________________________________
>>>>> rabbitmq-discuss mailing list
>>>>> rabbitmq-discuss at lists.rabbitmq.com
>>>>> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>>>>>
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140130/20b6a353/attachment.html>
More information about the rabbitmq-discuss
mailing list