V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
kslr
V2EX  ›  问与答

AWS SQS 是否有办法在处理时通过 AttributeName 过滤想要的数据的呢?

  •  
  •   kslr · 2017-10-19 23:32:06 +08:00 · 782 次点击
    这是一个创建于 2451 天前的主题,其中的信息可能已经有所发展或是发生改变。

    提交消息的时候 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 ?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1094 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:41 · PVG 02:41 · LAX 11:41 · JFK 14:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.