{"id":13413399,"url":"https://github.com/cheshir/go-mq","last_synced_at":"2025-12-30T00:47:34.810Z","repository":{"id":51364718,"uuid":"94796654","full_name":"cheshir/go-mq","owner":"cheshir","description":"Declare AMQP entities like queues, producers, and consumers in a declarative way. Can be used to work with RabbitMQ.","archived":false,"fork":false,"pushed_at":"2023-10-09T18:33:44.000Z","size":112,"stargazers_count":91,"open_issues_count":1,"forks_count":17,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-07-31T20:52:19.078Z","etag":null,"topics":["amqp","go","golang","hacktoberfest","rabbit","rabbitmq"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cheshir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2017-06-19T16:16:30.000Z","updated_at":"2024-07-26T23:49:45.000Z","dependencies_parsed_at":"2024-01-08T15:34:41.487Z","dependency_job_id":null,"html_url":"https://github.com/cheshir/go-mq","commit_stats":{"total_commits":68,"total_committers":7,"mean_commits":9.714285714285714,"dds":0.4558823529411765,"last_synced_commit":"5b3e9d1a6aa433ab66e309852a5c5fdd2086d43b"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheshir%2Fgo-mq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheshir%2Fgo-mq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheshir%2Fgo-mq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheshir%2Fgo-mq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheshir","download_url":"https://codeload.github.com/cheshir/go-mq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498745,"owners_count":16833056,"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","hacktoberfest","rabbit","rabbitmq"],"created_at":"2024-07-30T20:01:39.427Z","updated_at":"2025-12-30T00:47:34.781Z","avatar_url":"https://github.com/cheshir.png","language":"Go","funding_links":[],"categories":["GO","消息","Messaging","Relational Databases","消息系统","机器学习"],"sub_categories":["Manuals","检索及分析资料库","Search and Analytic Databases","Advanced Console UIs","SQL 查询语句构建库"],"readme":"[![Build Status](https://github.com/cheshir/go-mq/actions/workflows/go.yml/badge.svg)](https://github.com/cheshir/go-mq/actions/workflows/go.yml)\n[![codecov](https://codecov.io/gh/cheshir/go-mq/branch/master/graph/badge.svg)](https://codecov.io/gh/cheshir/go-mq)\n[![Go Report Card](https://goreportcard.com/badge/cheshir/go-mq)](https://goreportcard.com/report/github.com/cheshir/go-mq)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cheshir_go-mq\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cheshir_go-mq) \n[![GoDoc](https://godoc.org/github.com/cheshir/go-mq?status.svg)](https://godoc.org/github.com/cheshir/go-mq)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/cheshir/go-mq/blob/master/LICENSE)\n\n\n# About\n\nThis package provides an ability to encapsulate creation and configuration of RabbitMQ([AMQP])(https://www.amqp.org) entities \nlike queues, exchanges, producers and consumers in a declarative way with a single config.\n\nExchanges, queues and producers are going to be initialized in the background.\n\ngo-mq supports both sync and async producers.\n\ngo-mq has auto reconnects on closed connection or network error.\nYou can configure delay between each connect try using `reconnect_delay` option.\n\n### Minimal go version\n\n1.16\n\n## Install\n\n`go get -u github.com/cheshir/go-mq/v2`\n\n## API\n\nVisit [godoc](https://godoc.org/github.com/cheshir/go-mq) to get information about library API.\n\nFor those of us who preferred learn something new on practice there is working examples in `example` directory.\n\n## Configuration\n\nYou can configure mq using mq.Config struct directly or by filling it from config file.\n\nSupported configuration tags:\n\n* yaml\n* json\n* mapstructure\n\nAvailable options:\n\n```yaml\ndsn: \"amqp://login:password@host:port/virtual_host\" # Use comma separated list for cluster connection\nreconnect_delay: 5s                     # Interval between connection tries. Check https://golang.org/pkg/time/#ParseDuration for details.\ntest_mode: false                        # Switches library to use mocked broker. Defaults to false.\nexchanges:\n  - name: \"exchange_name\"\n    type: \"direct\"\n    options:\n      # Available options with default values:\n      auto_delete: false\n      durable: false\n      internal: false\n      no_wait: false\nqueues:\n  - name: \"queue_name\"\n    exchange: \"exchange_name\"\n    routing_key: \"route\"\n    # A set of arguments for the binding.\n    # The syntax and semantics of these arguments depend on the exchange class.\n    binding_options:\n      no_wait: false\n    # Available options with default values:\n    options:\n      auto_delete: false\n      durable: false\n      exclusive: false\n      no_wait: false\nproducers:\n  - name: \"producer_name\"\n    buffer_size: 10                      # Declare how many messages we can buffer during fat messages publishing.\n    exchange: \"exchange_name\"\n    routing_key: \"route\"\n    sync: false                          # Specify whether producer will worked in sync or async mode.\n    # Available options with default values:\n    options:\n      content_type:  \"application/json\"\n      delivery_mode: 2                   # 1 - non persistent, 2 - persistent.\nconsumers:\n  - name: \"consumer_name\"\n    queue: \"queue_name\"\n    workers: 1                           # Workers count. Defaults to 1.\n    prefetch_count: 0                    # Prefetch message count per worker.\n    prefetch_size: 0                     # Prefetch message size per worker.\n    # Available options with default values:\n    options:\n      no_ack: false\n      no_local: false\n      no_wait: false\n      exclusive: false\n```\n\n## Error handling\n\nAll errors are accessible via exported channel:\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/cheshir/go-mq\"\n)\n\nfunc main() {\n\tconfig := mq.Config{} // Set your configuration.\n\tqueue, _ := mq.New(config)\n\t// ...\n\n\tgo handleMQErrors(queue.Error())\n\t\n\t// Other logic.\n}\n\nfunc handleMQErrors(errors \u003c-chan error) {\n\tfor err := range errors {\n\t\tlog.Println(err)\n\t}\n}\n```\n\nIf channel is full – new errors will be dropped.\n\nErrors from sync producer won't be accessible from error channel because they returned directly.\n\n## Tests\n\nThere are some cases that can only be tested with real broker \nand some cases that can only be tested with mocked broker.\n \nIf you are able to run tests with a real broker run them with:\n\n`go test -mock-broker=0`\n\nOtherwise mock will be used.\n\n## Changelog\n\nCheck [releases page](https://github.com/cheshir/go-mq/releases).\n\n## How to upgrade\n\n### From v1 to v2\n\n* `New()` returns `*MessageQueue` not the interface.\n\n* Minimal go version updated to the 1.16.\n\n### From version 0.x to 1.x\n\n* `GetConsumer()` method was renamed to `Consumer()`. This is done to follow go guideline.\n\n* `GetProducer()` method was removed. Use instead `AsyncProducer()` or `SyncProducer()` if you want to catch net error by yourself.\n\n## Epilogue\n\nFeel free to create issues with bug reports or your wishes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheshir%2Fgo-mq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheshir%2Fgo-mq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheshir%2Fgo-mq/lists"}