{"id":13806978,"url":"https://github.com/viartemev/rabbitmq-kotlin","last_synced_at":"2025-04-11T02:12:19.457Z","repository":{"id":37829642,"uuid":"164432364","full_name":"viartemev/rabbitmq-kotlin","owner":"viartemev","description":"Kotlin coroutine based library for RabbitMQ","archived":false,"fork":false,"pushed_at":"2025-03-26T23:29:03.000Z","size":1147,"stargazers_count":116,"open_issues_count":14,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T02:12:06.239Z","etag":null,"topics":["amqp","coroutines","kotlin","kotlin-channel","kotlin-coroutines","kotlin-flow","library","rabbitmq","rabbitmq-client"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/viartemev.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":"2019-01-07T12:53:28.000Z","updated_at":"2024-11-30T09:49:52.000Z","dependencies_parsed_at":"2023-12-01T14:29:06.802Z","dependency_job_id":"1f21df1e-af37-469a-8797-8f3e9eea905d","html_url":"https://github.com/viartemev/rabbitmq-kotlin","commit_stats":null,"previous_names":["viartemev/the-white-rabbit"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viartemev%2Frabbitmq-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viartemev%2Frabbitmq-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viartemev%2Frabbitmq-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viartemev%2Frabbitmq-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viartemev","download_url":"https://codeload.github.com/viartemev/rabbitmq-kotlin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328160,"owners_count":21085261,"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","coroutines","kotlin","kotlin-channel","kotlin-coroutines","kotlin-flow","library","rabbitmq","rabbitmq-client"],"created_at":"2024-08-04T01:01:18.926Z","updated_at":"2025-04-11T02:12:19.427Z","avatar_url":"https://github.com/viartemev.png","language":"Kotlin","funding_links":[],"categories":["Integration","进程间通信"],"sub_categories":["Spring Cloud框架"],"readme":"# RabbitMQ Kotlin\n[![CI](https://github.com/viartemev/rabbitmq-kotlin/actions/workflows/gradle.yml/badge.svg?branch=master)](https://github.com/viartemev/rabbitmq-kotlin/actions/workflows/gradle.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThe RabbitMQ Kotlin Coroutine Library is designed to provide Kotlin developers with an efficient, coroutine-based approach to interact with RabbitMQ.  \nThis library simplifies message queue operations by integrating seamlessly with Kotlin's coroutines, offering a modern and reactive way to handle asynchronous messaging in Kotlin applications.   \nIt supports a variety of advanced features including queue and exchange manipulations, message publishing with confirmation, message consuming with acknowledgment, transactional operations, and the Remote Procedure Call (RPC) pattern.  \n\n## Features\n\n- **Queue and Exchange Manipulations**: Easily create, delete, and configure queues and exchanges. Supports all RabbitMQ exchange types (direct, topic, headers, fanout) and offers flexible options for queue bindings and attributes.\n- **Message Publishing with Confirmation**: Publish messages to queues with the option to receive confirmations, ensuring reliable delivery and handling of messages.\n- **Message Consuming with Acknowledgment**: Consume messages from queues with acknowledgment support, allowing for precise control over message processing and acknowledging.\n- **Transactional Publishing and Consuming**: Support for transactional operations, enabling the grouping of publish and consume actions into atomic units, ensuring data consistency and reliability.\n- **RPC Pattern Implementation**: Facilitates the implementation of the RPC pattern, allowing for easy setup of request-response message flows, suitable for service-oriented architectures.\n\n## Getting Started\nYou need to have [Java 8](https://www.oracle.com/technetwork/java/javase/downloads/index.html) installed.\n\n### Snapshots\n```gradle\nrepositories {\n    mavenCentral()\n    maven(\"https://s01.oss.sonatype.org/content/repositories/snapshots\")\n}\n\ndependencies {\n    implementation(\"io.github.viartemev:rabbitmq-kotlin:0.7.0-SNAPSHOT\")\n}\n```\n\n## Examples\nFull list of examples could be found [here](https://github.com/viartemev/rabbitmq-kotlin/tree/master/rabbitmq-kotlin-example/src/main)\n\n### Asynchronous message publishing with confirmation\n```kotlin\n    val connectionFactory = ConnectionFactory().apply { useNio() }\n    connectionFactory.newConnection().use { connection -\u003e\n        connection.confirmChannel {\n            declareQueue(QueueSpecification(PUBLISHER_QUEUE_NAME)).queue\n            publish {\n                (1..TIMES).map { createMessage(\"\") }.map { async(Dispatchers.IO) { publishWithConfirm(it) } }.awaitAll()\n                    .forEach { println(it) }\n            }\n        }\n    }\n```\n\n### Asynchronous message consuming with acknowledgement\nConsume only n-messages:\n```kotlin\nval connectionFactory = ConnectionFactory().apply { useNio() }\n    connectionFactory.newConnection().use { connction -\u003e\n        connction.channel {\n            consume(CONSUMER_QUEUE_NAME, 1) {\n                (1..CONSUME_TIMES).map { async(Dispatchers.IO) { consumeMessageWithConfirm(handler) } }.awaitAll()\n            }\n        }\n    }\n```\n\n### Transactional publishing and consuming\n\nRabbitMQ and AMQP itself offer rather scarce support for transaction. When considering using transactions you should be aware that:\n* a transaction could only span one channel and one queue;\n* `com.rabbitmq.client.Channel` is not thread-safe;\n* channel can be either in confirm mode or in transaction mode at a time;\n* transactions cannot be nested into each other;\n\n The library provides a convenient way to perform transactional publishing and receiving based on `transaction` extension function. This function commits a transaction upon normal execution of the block and rolls it back if a `RuntimeException` occurs. Exceptions are always propagated further. Coroutines are not used for publishing though, since there are no any asynchronous operations involved.\n\n```kotlin\nconnection.txChannel {\n    transaction {\n        val message = createMessage(queue = oneTimeQueue, body = \"Hello from tx\")\n        publish(message)\n    }\n}\n```\n\n### RPC pattern\n```kotlin\nConnectionFactory().apply { useNio() }.newConnection().use { conn -\u003e\n        conn.channel {\n            logger.info { \"Asking for greeting request...\" }\n            val response = withTimeoutOrNull(1000) {\n                async(Dispatchers.IO) {\n                    rpc {\n                        val result = call(message)\n                        logger.info { \"Got a message: ${String(result.body)}\" }\n                        result\n                    }\n                }.await()\n            }\n            if (response == null) {\n                logger.info { \"Timeout is exeeded\" }\n            } else {\n                logger.info { \"Result: ${String(response.body)}\" }\n            }\n        }\n    }\n```\n\n## Links\n* [Benchmarks](https://github.com/viartemev/the-white-rabbit/issues/88#issuecomment-470461937)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviartemev%2Frabbitmq-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviartemev%2Frabbitmq-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviartemev%2Frabbitmq-kotlin/lists"}