{"id":22468495,"url":"https://github.com/projectweekend/rmq-utils","last_synced_at":"2025-03-27T15:44:36.085Z","repository":{"id":28340238,"uuid":"31853624","full_name":"projectweekend/RMQ-Utils","owner":"projectweekend","description":"Automated RabbitMQ account and connection management.","archived":false,"fork":false,"pushed_at":"2015-03-15T15:20:21.000Z","size":180,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T11:20:03.149Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/projectweekend.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-08T14:59:33.000Z","updated_at":"2015-03-15T15:20:21.000Z","dependencies_parsed_at":"2022-09-10T19:10:16.078Z","dependency_job_id":null,"html_url":"https://github.com/projectweekend/RMQ-Utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FRMQ-Utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FRMQ-Utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FRMQ-Utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2FRMQ-Utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/projectweekend","download_url":"https://codeload.github.com/projectweekend/RMQ-Utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245874185,"owners_count":20686721,"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":[],"created_at":"2024-12-06T11:16:59.408Z","updated_at":"2025-03-27T15:44:36.064Z","avatar_url":"https://github.com/projectweekend.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a work in progress. I had a need for some services to automate admin tasks in RabbitMQ, so I decided to start building some things.\n\n\n### Account Creator\n\nThis is a class that makes one connection to the Rabbit Admin API and one to a direct exchange/queue named: `rmq_utils/account_creator`. It listens for messages, creates a new user/password/vhost via the Rabbit Admin API, and calls a `post_create` method for each. The message must be a JSON object:\n\n```json\n{\n    \"user_key\": \"whatever\"\n}\n```\n\nThe `post_create` method is implemented in your sub-class. It will receive two input parameters:\n\n* `user_key` - The same value received in the message\n* `credentials` - A dictionary representing the Rabbit account info for the account that was just created. It has the following keys: `username`, `password`, `vhost`\n\n**Example:**\n```python\nfrom rmq_utils import AccountCreator\n\n\nRABBIT_URL = 'rabbit-url-to-listen-for-messages'\nROUTING_KEY = 'unique-key-for-server'\nADMIN_HOST = 'rabbit-admin-host'\nADMIN_USER = 'admin-user'\nADMIN_PASSWORD = 'admin-password'\n\n\nclass ExampleAccountCreator(AccountCreator):\n\n    @staticmethod\n    def post_create(user_key, creds):\n        # Do whatever you want here, perhaps make a call to\n        # update a record in a database using the user_key\n        print('{0}: {1}'.format(user_key, creds['username']))\n\n\ndef main():\n    creator = ExampleAccountCreator(\n        rabbit_url=RABBIT_URL,\n        routing_key=ROUTING_KEY,\n        mgmt_host=ADMIN_HOST,\n        mgmt_user=ADMIN_USER,\n        mgmt_password=ADMIN_PASSWORD)\n    try:\n        creator.run()\n    except KeyboardInterrupt:\n        creator.stop()\n\n\nif __name__ == '__main__':\n    main()\n```\n\n\n### Account Destroyer\n\nThis is a class that makes one connection to the Rabbit Admin API and one to a direct exchange/queue named: `rmq_utils/account_destroyer`. It listens for messages, deletes an existing user/vhost via the Rabbit Admin API, and calls a `post_delete` method for each. The message must be a JSON object:\n\n```json\n{\n    \"user_key\": \"whatever\",\n    \"rabbit_user\": \"the_username\"\n}\n```\n\nThe `post_delete` method is implemented in your sub-class. It will receive one input parameter:\n\n* `user_key` - The same value received in the message\n\n**Example:**\n```python\nfrom rmq_utils import AccountDestroyer\n\n\nRABBIT_URL = 'rabbit-url-to-listen-for-messages'\nROUTING_KEY = 'unique-key-for-server'\nADMIN_HOST = 'rabbit-admin-host'\nADMIN_USER = 'admin-user'\nADMIN_PASSWORD = 'admin-password'\n\n\nclass ExampleAccountDestroyer(AccountDestroyer):\n\n    @staticmethod\n    def post_delete(user_key):\n        # Do whatever you want here, perhaps make a call to\n        # update a record in a database using the user_key\n        print('{0}'.format(user_key))\n\n\ndef main():\n    destroyer = ExampleAccountDestroyer(\n        rabbit_url=RABBIT_URL,\n        routing_key=ROUTING_KEY,\n        mgmt_host=ADMIN_HOST,\n        mgmt_user=ADMIN_USER,\n        mgmt_password=ADMIN_PASSWORD)\n    try:\n        destroyer.run()\n    except KeyboardInterrupt:\n        destroyer.stop()\n\n\nif __name__ == '__main__':\n    main()\n```\n\n\n### Connection Limiter\n\nThis service maintains a map of usernames to an array of connection names. It calls a user-defined method (`max_connections_by_user`) that returns a map of usernames to integers representing the maximum number of concurrent connections allowed for each. It compares the current number of open connections for each to the max, if above the maximum it closes connections to maintain the maximum.\n\n**Example:**\n```python\nfrom rmq_utils import ConnectionLimiter\n\n\nclass ExampleConnectionLimiter(ConnectionLimiter):\n\n    @staticmethod\n    def max_connections_by_user():\n        # Do whatever you want here, perhaps make a call to\n        # a database to get the max connection per user\n        return {\n            'test': 1\n        }\n\ndef main():\n    limiter = ExampleConnectionLimiter(\n        mgmt_host=ADMIN_HOST,\n        mgmt_user=ADMIN_USER,\n        mgmt_password=ADMIN_PASSWORD)\n    try:\n        limiter.run()\n    except KeyboardInterrupt:\n        pass\n\n\nif __name__ == '__main__':\n    main()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Frmq-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojectweekend%2Frmq-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Frmq-utils/lists"}