消息"/>
从Amazon SQS获取特定消息
是否有任何方法可以通过某些ID检索邮件。在此answer中写道,这是不可能的。但是由于答案是旧的,所以我再次询问它是否仍然相同。
我正在通过以下方式发送消息-
const params = {
DelaySeconds: 0,
MessageAttributes: {
test: {
DataType: 'String',
StringValue: 'bdbdh',
},
},
MessageBody: JSON.stringify({
AccountId: '100'
}),
QueueUrl: 'url',
};
return new Promise((resolve, reject) => {
sqs.sendMessage(params, function(err, data) {
if (err) {
console.log('data', err);
reject(err);
} else {
console.log('data', data);
resolve(data);
}
});
});
以下面的方式检索消息-
const params = {
MaxNumberOfMessages: 10,
MessageAttributeNames: ["test"],
VisibilityTimeout: 600,
QueueUrl: 'url',
};
return new Promise((resolve, reject) => {
sqs.receiveMessage(params, function(err, data) {
if (err) {
console.log('data', err);
reject(err);
} else {
console.log('data', data);
resolve(data);
}
});
});
我也试图通过属性名称获取消息,但没有运气。
回答如下:[不幸的是,我认为没有办法通过id从sqs中提取。
根据SQS文档,没有可以传递的参数:
var params = {
QueueUrl: 'STRING_VALUE', /* required */
AttributeNames: [
All | Policy | VisibilityTimeout | MaximumMessageSize | MessageRetentionPeriod | ApproximateNumberOfMessages | ApproximateNumberOfMessagesNotVisible | CreatedTimestamp | LastModifiedTimestamp | QueueArn | ApproximateNumberOfMessagesDelayed | DelaySeconds | ReceiveMessageWaitTimeSeconds | RedrivePolicy | FifoQueue | ContentBasedDeduplication | KmsMasterKeyId | KmsDataKeyReusePeriodSeconds,
/* more items */
],
MaxNumberOfMessages: 'NUMBER_VALUE',
MessageAttributeNames: [
'STRING_VALUE',
/* more items */
],
ReceiveRequestAttemptId: 'STRING_VALUE',
VisibilityTimeout: 'NUMBER_VALUE',
WaitTimeSeconds: 'NUMBER_VALUE'
};
sqs.receiveMessage(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
AWS SQS docs
更多推荐
从Amazon SQS获取特定消息
发布评论