Amazon SQS消息正文与消息属性相对的目的 [英] Purpose of Amazon SQS message's body as against message's attributes

查看:127
本文介绍了Amazon SQS消息正文与消息属性相对的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在已经可以添加消息属性的同时在SQS中使用消息正文的目的是什么?

What is the purpose of using message body in SQS while you're already able to add message attributes?

让我们举个例子,我们想在新用户注册时将消息推送到new-user队列,我想消息将具有属性userId,在这里看不到body的用途.

Let's take an example, we want to push a message to new-user queue when a new user registered, I imagine the message will have an attribute userId, I don't see the use of body here.

推荐答案

消息属性应该用作消息元数据(例如时间戳或可能的某些类别),而不是消息本身.

Message attributes are supposed to be used as message metadata (like timestamp or possibly some category) and not the message itself.

理想情况下,消息有效载荷应在消息正文中给出

Ideally, message payload should be given in the message body

因此,例如,如果您支持JSON和XML有效负载,则可以将有效负载类型作为消息属性,然后在获取消息时,根据此有效负载类型属性,您可以在JSON消息处理器或XML消息处理器之间进行选择.这只是一个肤浅的例子,用来解释属性和主体的用法

So, for example if you are supporting JSON and XML payloads then possibly you can put payload type as message attribute and then when you fetch the message, based on this payload type attribute you decide between the JSON message processor or XML message processor. This is just a superficial example to explain the usage of attributes and body

以下是AWS Doc的摘录

Following is the extract from AWS Doc

Amazon SQS提供对消息属性的支持.邮件属性允许您提供有关邮件的结构化元数据项(例如时间戳,地理空间数据,签名和标识符).消息属性是可选的,与消息正文分开但随消息正文一起发送.消息的接收者可以使用此信息来帮助决定如何处理消息,而不必先处理消息主体.每个消息最多可以具有10个属性.要指定消息属性,您可以使用AWS管理控制台,AWS软件开发套件(SDK)或查询API.

Amazon SQS provides support for message attributes. Message attributes allow you to provide structured metadata items (such as timestamps, geospatial data, signatures, and identifiers) about the message. Message attributes are optional and separate from, but sent along with, the message body. This information can be used by the receiver of the message to help decide how to handle the message without having to first process the message body. Each message can have up to 10 attributes. To specify message attributes, you can use the AWS Management Console, AWS software development kits (SDKs), or query API.

这篇关于Amazon SQS消息正文与消息属性相对的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆