{"id":19859146,"url":"https://github.com/woorui/aws-msg","last_synced_at":"2025-02-28T22:23:10.988Z","repository":{"id":43827013,"uuid":"459890389","full_name":"woorui/aws-msg","owner":"woorui","description":"AWS SQS Pub/Sub Primitives implemented by aws-sdk-go-v2","archived":false,"fork":false,"pushed_at":"2022-09-14T02:39:13.000Z","size":66,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T14:28:58.263Z","etag":null,"topics":["aws","aws-sdk","go-msg","pubsub","sqs","sqs-queue"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/woorui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-16T07:05:14.000Z","updated_at":"2023-03-04T05:31:58.000Z","dependencies_parsed_at":"2023-01-18T07:00:34.559Z","dependency_job_id":null,"html_url":"https://github.com/woorui/aws-msg","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Faws-msg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Faws-msg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Faws-msg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woorui%2Faws-msg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/woorui","download_url":"https://codeload.github.com/woorui/aws-msg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241255358,"owners_count":19934846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-sdk","go-msg","pubsub","sqs","sqs-queue"],"created_at":"2024-11-12T14:25:50.594Z","updated_at":"2025-02-28T22:23:10.961Z","avatar_url":"https://github.com/woorui.png","language":"Go","readme":"# aws-msg\n\n![build](https://github.com/woorui/aws-msg/actions/workflows/go.yml/badge.svg)\n[![codecov](https://codecov.io/gh/woorui/aws-msg/branch/main/graph/badge.svg?token=Y0030WHH14)](https://codecov.io/gh/woorui/aws-msg)\n\n## Overview\n\nPackage aws-msg implements pub/sub primitives outlined in package \"github.com/zerofox-oss/go-msg\".\n\nIt's built on top of \"github.com/aws/aws-sdk-go-v2\".\n\n## Why use\n\n1. Elegant pub/sub API from https://github.com/zerofox-oss/go-msg\n\n2. Support multiple goroutinue to pull messages from SQS; The receive speed is significantly improved.\n\n3. Support graceful shutdown.\n\n4. Backpressure for handling SQS message.\n\n## Install \n\n```\ngo get github.com/woorui/aws-msg\n```\n\n## Examples\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/aws/aws-sdk-go-v2/config\"\n\t\"github.com/aws/aws-sdk-go-v2/credentials\"\n\t\"github.com/aws/aws-sdk-go-v2/service/sqs\"\n\tsqsmsg \"github.com/woorui/aws-msg/sqs\"\n\t\"github.com/zerofox-oss/go-msg\"\n)\n\nvar (\n\tregion    = \"cn-northwest-1\"\n\tkey       = \"QNWIOCMEROCVSL\"\n\tsecret    = \"aswekdpa[veverjiwAmioeoqxkaij\"\n\tqueueName = \"the-queue-name\"\n)\nvar client *sqs.Client\n\nfunc init() {\n\tcfg, err := config.LoadDefaultConfig(\n\t\tcontext.TODO(),\n\t\tconfig.WithRegion(region),\n\t\tconfig.WithCredentialsProvider(\n\t\t\tcredentials.NewStaticCredentialsProvider(key, secret, \"\"),\n\t\t),\n\t)\n\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tclient = sqs.NewFromConfig(cfg)\n}\n\n// ExampleServer dumps SQS message to ./messages.log for 5 seconds\nfunc ExampleServer() {\n\tserver, err := sqsmsg.NewServer(queueName, client)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tgo func() {\n\t\terr = server.Serve(dumpToPath(\"./messages.log\"))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t}()\n\n\ttime.Sleep(5 * time.Second)\n\n\tserver.Shutdown(context.TODO())\n}\n\n// ExampleTopic show how to send an SQS message\nfunc ExampleTopic() {\n\tctx := context.Background()\n\n\ttopic, err := sqsmsg.NewTopic(ctx, queueName, client)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tuserCtx := context.Background()\n\n\tw := topic.NewWriter(userCtx)\n\n\tif _, err = w.Write([]byte(\"hello world\")); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tif err := w.Close(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n\n// fileLog write sqs message to local file\n// fileLog implement msg.Receiver\ntype fileLog struct {\n\tf *os.File\n}\n\nfunc dumpToPath(path string) *fileLog {\n\tf, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn \u0026fileLog{f: f}\n}\n\nfunc (f *fileLog) Receive(c context.Context, m *msg.Message) error {\n\tcontents, _ := ioutil.ReadAll(m.Body)\n\tf.f.Write([]byte{'\\n'})\n\t_, err := f.f.Write(contents)\n\treturn err\n}\n\n```\n\n## Reference\n\nhttps://github.com/zerofox-oss/go-msg\n\nhttps://github.com/aws/aws-sdk-go-v2\n\nhttps://github.com/zerofox-oss/go-aws-msg\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoorui%2Faws-msg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwoorui%2Faws-msg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoorui%2Faws-msg/lists"}