Skip to content

Commit

Permalink
Change name of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemyev Vyacheslav authored and Artemyev Vyacheslav committed Nov 13, 2023
1 parent a7877db commit 7c97e66
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 48 deletions.
42 changes: 7 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<img src=https://github.com/viartemev/the-white-rabbit/assets/23705041/1bd2825b-1241-49d8-94fc-550c381969de width="200" height="200">

# RabbitMQ Kotlin
# RabbitMQ Kotlin
[![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)
[![Open Source Helpers](https://www.codetriage.com/viartemev/the-white-rabbit/badges/users.svg)](https://www.codetriage.com/viartemev/the-white-rabbit)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand All @@ -13,43 +13,15 @@ The White Rabbit is a [fast](https://github.com/viartemev/the-white-rabbit/issue
* Message consuming with acknowledgment
* Transactional publishing and consuming
* RPC pattern

## Adding to project
<details><summary>Gradle</summary>

```
repositories {
jcenter()
}
compile 'com.viartemev:the-white-rabbit:$version'
```
</details>

<details><summary>Maven</summary>

```
<repositories>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>
<dependency>
<groupId>com.viartemev</groupId>
<artifactId>the-white-rabbit</artifactId>
<version>${version}</version>
</dependency>
```
</details>
## Adding to project

## Usage notes and examples

Use one of the extension methods on `com.rabbitmq.client.Connection` to get a channel you need:
Use one of the extension methods on `com.rabbitmq.client.Connection` to get a channel you need:

```kotlin
connection.channel {
connection.channel {
/*
The plain channel with consumer acknowledgments, supports:
-- queue and exchange manipulations
Expand All @@ -58,7 +30,7 @@ connection.channel {
*/
}

connection.confirmChannel { //
connection.confirmChannel { //
/*
Channel with publisher confirmations, additionally supports:
-- asynchronous message publishing
Expand Down Expand Up @@ -86,7 +58,7 @@ connection.channel.declareQueue(QueueSpecification(QUEUE_NAME))
connection.channel.bindQueue(BindQueueSpecification(EXCHANGE_NAME, QUEUE_NAME))
```

### Asynchronous message publishing with confirmation
### Asynchronous message publishing with confirmation
```kotlin
connection.confirmChannel {
publish {
Expand Down Expand Up @@ -126,7 +98,7 @@ RabbitMQ and AMQP itself offer rather scarce support for transaction. When consi
* transactions cannot be nested into each other;

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.

```kotlin
connection.txChannel {
transaction {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ configure(rootProject) {
}
}

project("the-white-rabbit-example") {
project("rabbitmq-kotlin-example") {
dependencies {
implementation(rootProject)
implementation("org.slf4j:slf4j-api:2.0.9")
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = 'the-white-rabbit'
rootProject.name = 'rabbitmq-kotlin'

include('benchmarks')
include('the-white-rabbit-example')
include('rabbitmq-kotlin-example')
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.viartemev.thewhiterabbit

import com.rabbitmq.client.Connection
import com.rabbitmq.client.ConnectionFactory
import com.rabbitmq.http.client.Client
import com.viartemev.thewhiterabbit.utils.RabbitMQContainer
Expand All @@ -20,6 +21,7 @@ abstract class AbstractTestContainersTest {

lateinit var factory: ConnectionFactory
lateinit var httpRabbitMQClient: Client
lateinit var connection: Connection
val DEFAULT_VHOST = "/"

@BeforeAll
Expand All @@ -29,5 +31,6 @@ abstract class AbstractTestContainersTest {
factory.port = rabbitmq.connectionPort()
httpRabbitMQClient =
Client(URL("http://${rabbitmq.host}:${rabbitmq.managementPort()}/api/"), "guest", "guest")
connection = factory.newConnection()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class ConsumerFlowTest : AbstractTestContainersTest() {
private val QUEUE_NAME = "test_queue"
private val connection = factory.newConnection()

private suspend fun generateMessages(count: Int) = coroutineScope {
connection.channel {
Expand All @@ -35,9 +32,7 @@ class ConsumerFlowTest : AbstractTestContainersTest() {
val messagesCount = 100
generateMessages(messagesCount)
connection.channel {
ConsumerFlow(this, QUEUE_NAME)
.consumerAutoAckFlow(2)
.take(messagesCount)
ConsumerFlow(this, QUEUE_NAME).consumerAutoAckFlow(2).take(messagesCount)
.collect { delivery -> println(String(delivery.body)) }
}
}
Expand All @@ -47,10 +42,7 @@ class ConsumerFlowTest : AbstractTestContainersTest() {
val messagesCount = 10
generateMessages(messagesCount)
connection.channel {
ConsumerFlow(this, QUEUE_NAME)
.consumerConfirmAckFlow(2)
.flowOn(Dispatchers.IO)
.take(messagesCount)
ConsumerFlow(this, QUEUE_NAME).consumerConfirmAckFlow(2).flowOn(Dispatchers.IO).take(messagesCount)
.catch { e -> println("Caught exception: $e") }.collect { delivery ->
println("Got the message: ${delivery.body}")
}
Expand Down

0 comments on commit 7c97e66

Please sign in to comment.