简体   繁体   English

AWS SNS SQS - 订阅过滤策略

[英]AWS SNS SQS - Subscription filter policy

I would like to send messages with Subscription filter policy SNS to SQS and then to lambda.我想将带有订阅过滤策略 SNS 的消息发送到 SQS,然后再发送到 lambda。

If I apply the filter, I don't receive any message in lambda.如果我应用过滤器,我不会在 lambda 中收到任何消息。

Here is the message:这是消息:

{
  "aggregateType": "APPOINTMENT",
  "aggregateId": "4756c2b0-a579-4785-8eb2-5dae356d415b",
  "eventType": "MODIFIED",
  "eventTimestamp": "2022-04-28T08:02:03Z",
  "eventBody": {
    "createdDate": null,
    "lastModifiedDate": "2020-08-18T11:00:32.288748Z",
    "createdBy": null,
    "lastModifiedBy": "WiredUser:ds18817",
    "id": "4756c2b0-a579-4785-8eb2-5dae356d415b",
    "dealerId": "72417900_001",
    "context": "AFTERSALES",
    "type": "RESTITUTION",
    "description": "Reparación mecánica - modified",
    "dateTime": "2020-08-18T14:15:00Z",
    "origin": "RDS",
    "status": "CONCLUDED",
    "contractType": "D",
    "notificationChannels": [
      "SMS"
    ],
    "vehicle": {
      "vin": "VF1JZ0Y0E43339071",
      "brand": "RENAULT",
      "model": "SCENIC III",
      "mileage": 205000,
      "version": "SCENIC III",
      "regNumber": "2392GWR",
      "mileageUnit": "km"
    },
    "dmsId": "2786850",
    "wazyPostRequestId": null,
    "wazyPutRequestId": "a4195986-06a3-4641-80c2-081d3f83d15c",
    "customer": {
      "type": "P",
      "lastName": "RODRIGUEZ",
      "firstName": "ELENA",
      "contactPhone": "+34",
      "contactMobilePhone": "+34660211911"
    },
    "details": {
      "comments": [
        {
          "owner": "RECEPTOR",
          "number": 1,
          "comment": "REVSIAR CONTROLES\n"
        }
      ],
      "relatedObjects": [
        {
          "id": "1d058661-7edc-44e0-9a56-db632ca7e8eb",
          "type": "CONFIRMATION_SMS"
        },
        {
          "id": "2786850",
          "name": "DMS_APPT",
          "type": "DMS_APPT"
        },
        {
          "id": "2ca45b88-bc25-41c4-8e85-caf581312905",
          "name": "Reception appt",
          "type": "RECEPTION_APPT"
        },
        {
          "id": "4652290f-06bb-4b50-89a9-c635f5257af6",
          "name": "INTERVENTION_LIST",
          "type": "INTERVENTION_LIST"
        }
      ],
      "deliveryServices": [
        {
          "id": "31",
          "name": "Reparación mecánica",
          "type": "MECHANIC",
          "price": "0",
          "currency": "EUR",
          "hoursNeeded": 0.5,
          "durationNeeded": 1800.000000000
        }
      ]
    }
  }
}

Here is the Subscription filter policy:这是订阅过滤策略:

{
  "aggregateType": [
    "APPOINTMENT"
  ],
  "eventType": [
    "MODIFIED"
  ],
  "eventbody.status": [
    "INVOICE"
  ]
}

Do you know reason why I can't receive the message with this filter, please?请问您知道为什么我无法使用此过滤器收到消息吗?

Thanks for answer.感谢您的回答。

This is expected since the message does not match the filter.这是意料之中的,因为消息与过滤器不匹配。 In the given message your eventbody.status="CONCLUDED", therefore does not equal to "INVOICE".在给定的消息中,您的 eventbody.status="CONCLUDED",因此不等于“INVOICE”。

Check the documentation about applying OR across different attributes:查看有关跨不同属性应用 OR 的文档:

Currently, you can't use SNS filters to apply OR logic across different message attributes.目前,您不能使用 SNS 过滤器跨不同的消息属性应用 OR 逻辑。 Instead, you can use multiple SNS subscriptions with different endpoints to achieve the same effect.相反,您可以使用具有不同端点的多个 SNS 订阅来实现相同的效果。 For example, assume that you have message attributes named customer_interests and customer_preferences.例如,假设您有名为 customer_interests 和 customer_preferences 的消息属性。 To apply OR logic across both attributes, create an SNS subscription to match each message attribute.要对这两个属性应用 OR 逻辑,请创建一个 SNS 订阅以匹配每个消息属性。 Then, you can use your subscriber application to consume both types of messages through the different endpoints.然后,您可以使用您的订阅者应用程序通过不同的端点使用这两种类型的消息。

https://docs.aws.amazon.com/sns/latest/dg/and-or-logic.html https://docs.aws.amazon.com/sns/latest/dg/and-or-logic.html

Greetings问候

Thanks, palvarez.谢谢,帕尔瓦雷斯。

I found out we must use message attributes not message body for filtering.我发现我们必须使用消息属性而不是消息正文进行过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM