{"id":13714263,"url":"https://github.com/itcomusic/amqpx","last_synced_at":"2025-09-08T09:32:34.286Z","repository":{"id":48724728,"uuid":"510287493","full_name":"itcomusic/amqpx","owner":"itcomusic","description":"An AMQP 0.9.1 Go client","archived":false,"fork":false,"pushed_at":"2024-04-28T16:20:11.000Z","size":149,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-14T01:33:22.690Z","etag":null,"topics":["amqp","go","golang","rabbitmq"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itcomusic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-04T09:08:49.000Z","updated_at":"2024-04-28T16:20:14.000Z","dependencies_parsed_at":"2023-01-29T12:01:40.344Z","dependency_job_id":"40e0d5cc-0678-44ce-9604-da240ade6c4f","html_url":"https://github.com/itcomusic/amqpx","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itcomusic%2Famqpx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itcomusic%2Famqpx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itcomusic%2Famqpx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itcomusic%2Famqpx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itcomusic","download_url":"https://codeload.github.com/itcomusic/amqpx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242048559,"owners_count":20063404,"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":["amqp","go","golang","rabbitmq"],"created_at":"2024-08-02T23:01:55.899Z","updated_at":"2025-03-05T15:18:27.620Z","avatar_url":"https://github.com/itcomusic.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# RabbitMQ Go Client\n\n[![build-img]][build-url]\n[![pkg-img]][pkg-url]\n[![coverage-img]][coverage-url]\n\nThis is a Go AMQP 0.9.1 client wraps [amqp091-go](https://github.com/rabbitmq/amqp091-go) with support generics\n\n* Support of the encoding messages\n    * defaults encoding (json, protobuf, protojson)\n    * support of custom marshal/unmarshal functions\n* Middleware for easy integration\n\n## Installation\n\nGo version 1.20+\n\n```bash\ngo get github.com/itcomusic/amqpx\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"context\" \n\t\"fmt\"\n\t\n\t\"github.com/itcomusic/amqpx\"\n)\n\nfunc main() {\n    conn, _ := amqpx.Connect()\n    defer conn.Close()\n\n    // simple publisher\n    pub := amqpx.NewPublisher[[]byte](conn, amqpx.Direct, amqpx.UseRoutingKey(\"routing_key\"))\n    _ = pub.Publish(amqpx.NewPublishing([]byte(\"hello\")).PersistentMode(), amqpx.SetRoutingKey(\"override_routing_key\"))\n\t\n    // simple consumer \n    _ = conn.NewConsumer(\"foo\", amqpx.D(func(ctx context.Context, req *amqpx.Delivery[[]byte]) amqpx.Action {\n        fmt.Printf(\"received message: %s\\n\", string(*req.Msg))\n        return amqpx.Ack\n    }))\n}\n```\n\n### Publisher \u0026 consumer struct\n\nPretty using struct and avoiding boilerplate marhsal/unmarshal. It is strict compared content-type of the message and\ninvalid body is rejected.\n\n```go\n    conn, _ := amqpx.Connect(\n        amqpx.UseUnmarshaler(amqpxproto.NewUnmarshaler()), // global unmarshalers\n        amqpx.UseMarshaler(amqpxproto.NewMarshaler())), // global marshaler\n    defer conn.Close()\n\n    type Gopher struct {\n        Name string\n    }\n\t\n    // override default marshaler\n    pub := amqpx.NewPublisher[Gopher](conn, amqpx.Direct, amqpx.SetMarshaler(amqpxjson.Marshaler)) \n    _ = pub.Publish(amqpx.NewPublishing(Gopher{Name: \"Rob\"}), amqpx.SetRoutingKey(\"routing_key\"))\n\t\n    // override default unmarshaler\n    _ = conn.NewConsumer(\"bar\", amqpx.D(func(ctx context.Context, req *amqpx.Delivery[Gopher]) amqpx.Action {\n        fmt.Printf(\"user-id: %s, received message: %s\\n\", req.Req.UserID, req.Msg.Name)\n        return amqpx.Ack\n    }), amqpx.SetUnmarshaler(amqpxjson.Unmarshaler), amqpx.SetAutoAckMode())\n```\n\n### Consumer rate limiting\n\nThe Prefetch count informs the server will deliver that many messages to consumers before acknowledgments are received.\nThe Concurrency option limits numbers of goroutines of consumer, depends on prefetch count and auto-ack mode.\n\n```go\n    // prefetch count\n    _ = conn.NewConsumer(\"foo\", amqpx.D(func(ctx context.Context, req *amqpx.Delivery[[]byte]) amqpx.Action {\n        fmt.Printf(\"received message: %s\\n\", string(*req.Msg))\n        return amqpx.Ack\n    }), amqpx.SetPrefetchCount(8))\n\n    // limit goroutines\n\t_ = conn.NewConsumer(\"foo\", amqpx.D(func(ctx context.Context, req *amqpx.Delivery[[]byte]) amqpx.Action {\n        fmt.Printf(\"received message: %s\\n\", string(*req.Body))\n        return amqpx.Ack\n    }), amqpx.SetAutoAckMode(), amqpx.SetConcurrency(32))\n```\n\n### Declare queue\n\nThe declare queue, exchange and binding queue.\n\n```go\n    _ = conn.NewConsumer(\"foo\", amqpx.D(func(ctx context.Context, req *amqpx.Delivery[[]byte]) amqpx.Action {\n        fmt.Printf(\"received message: %s\\n\", string(*req.Msg))\n        return amqpx.Ack\n    }), amqpx.DeclareQueue(amqpx.QueueDeclare{AutoDelete: true}),\n        amqpx.DeclareExchange(amqpx.ExchangeDeclare{Name: \"exchange_name\", Type: amqpx.Direct}),\n        amqpx.BindQueue(amqpx.QueueBind{Exchange: \"exchange_name\", RoutingKey: []string{\"routing_key\"}}))\n```\n\n### Middleware\n\nPredefined support opentelemetry using interceptor.\n\n```go\n    import (\n        \"github.com/itcomusic/amqpx\"\n        \"github.com/itcomusic/amqpx/amqpxotel\"\n    )\n\n    // global\n    conn, _ := amqpx.Connect(amqpx.UserInterceptor(amqpxotel.NewInterceptor())\n    defer conn.Close()\n\n    // can use special interceptor for publisher\n    _ = amqpx.NewPublisher[[]byte](conn, amqpx.Direct, amqpx.SetPublishInterceptor(func(next amqpx.PublisherFunc) amqpx.PublisherFunc {\n        return func(ctx context.Context, m *amqpx.PublishingRequest) error {\n            fmt.Printf(\"message: %s\\n\", m.Body)\n            return next(m)\n        }\n    }))\n```\n\n## License\n\n[MIT License](LICENSE)\n\n[build-img]: https://github.com/itcomusic/amqpx/workflows/build/badge.svg\n\n[build-url]: https://github.com/itcomusic/amqpx/actions\n\n[pkg-img]: https://pkg.go.dev/badge/github.com/itcomusic/amqpx.svg\n\n[pkg-url]: https://pkg.go.dev/github.com/itcomusic/amqpx\n\n[coverage-img]: https://codecov.io/gh/itcomusic/amqpx/branch/main/graph/badge.svg\n\n[coverage-url]: https://codecov.io/gh/itcomusic/amqpx","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitcomusic%2Famqpx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitcomusic%2Famqpx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitcomusic%2Famqpx/lists"}