简体   繁体   English

在 golang 中订阅 SNS 主题和/或 SQS 队列?

[英]Subscribe to an SNS topic and / or SQS queue in golang?

I know how to do this in java, but I just can't figure it out in Go at all.我知道如何在 Java 中执行此操作,但我根本无法在 Go 中弄清楚。

All I want to do, is have a way to detect that an item got created in an S3 bucket, then have that trigger an SNS topic, which then notifies me of the file location in S3.我想要做的就是有一种方法来检测在 S3 存储桶中创建的项目,然后触发 SNS 主题,然后通知我 S3 中的文件位置。

Has anybody got a working example of how I can do the go side of this for subscribing to the SNS topic or the SNS queue if I need one?如果我需要订阅 SNS 主题或 SNS 队列,是否有人有一个工作示例,说明我如何执行此操作? Because all I seem to be able to find is Java and Node.因为我似乎只能找到 Java 和 Node.js。 I can find publish examples for go, but they are of little use to my use case.我可以找到 go 的发布示例,但它们对我的用例几乎没有用。

To use SNS you will need a simple HTTP/HTTPS endpoint to receive SNS notifications.要使用 SNS,您需要一个简单的 HTTP/HTTPS 端点来接收 SNS 通知。 Which is divided into two parts (Confirm the subscription and Processing messages from HTTP/HTTPS endpoint)分为两部分(确认订阅和处理来自 HTTP/HTTPS 端点的消息)

1. Confirm the subscription Do something as simple as this: 1. 确认订阅做一些像这样简单的事情:

func confirmSubscription(subcribeURL string) {
    response, err := http.Get(subcribeURL)
    if err != nil {
        fmt.Printf("Unbale to confirm subscriptions")
    } else {
        fmt.Printf("Subscription Confirmed sucessfully. %d", response.StatusCode)
    }
}

2. Processing messages from HTTP/HTTPS endpoint 2. 处理来自 HTTP/HTTPS 端点的消息

Parse the request's body, the documentations mentions how the body should be structured.解析请求的正文, 文档中提到了正文的结构。

Sources:资料来源:

https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html

https://github.com/viveksyngh/aws-sns-subscriber/blob/master/subscriber/subscriber.go https://github.com/viveksyngh/aws-sns-subscriber/blob/master/subscriber/subscriber.go

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

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