提交消息的时候 message 携带了消息属性字段,比如由谁谁谁来单独处理。
{
'Id': '1',
'MessageBody': 'world'
},
{
'Id': '2',
'MessageBody': 'boto3',
'MessageAttributes': {
'Author': {
'StringValue': 'Daniel',
'DataType': 'String'
}
}
}
但是发现在处理的时候只能根据属性名称过滤,没有办法根据内容处理。
for message in queue.receive_messages(MessageAttributeNames=['Author']):
# Get the custom author message attribute if it was set
author_text = ''
if message.message_attributes is not None:
author_name = message.message_attributes.get('Author').get('StringValue')
if author_name:
author_text = ' ({0})'.format(author_name)
# Print out the body and author (if set)
print('Hello, {0}!{1}'.format(message.body, author_text))
# Let the queue know that the message is processed
message.delete()
假如每次都要拿到数据判断一下再放回去,这样进程就会陷入恶性竞争吧?
速度比较快的 work 永远让消息处于不可用中,有没有办法只获得某种特殊类型的消息呢?
比如 Author = Daniel ?