Skip to content

Commit

Permalink
Merge pull request #146 from viartemev/add-main-example
Browse files Browse the repository at this point in the history
Add main example
  • Loading branch information
viartemev committed Mar 13, 2019
2 parents 87d5742 + d5d9c9e commit 8159742
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
13 changes: 5 additions & 8 deletions benchmarks/src/jmh/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%highlight(%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n)</pattern>
</encoder>
</appender>
<?xml version="1.0" encoding="UTF-8"?>

<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg%n</pattern>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="STDOUT"/>
</root>

</configuration>
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ project('the-white-rabbit-vertx-example') {
}
}

project('the-white-rabbit-example') {
dependencies {
compile rootProject
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.8.0-beta4'
runtime group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.0-alpha4'
runtime group: 'ch.qos.logback', name: 'logback-core', version: '1.3.0-alpha4'
}
}

project('benchmarks') {
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "me.champeau.gradle.jmh"
Expand All @@ -216,3 +225,4 @@ project('benchmarks') {
}
jmhCompileGeneratedClasses.finalizedBy deleteEmptyBmList
}

1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pluginManagement {
rootProject.name = 'the-white-rabbit'

include('benchmarks')
include('the-white-rabbit-example')
include('the-white-rabbit-ktor-example')
include('the-white-rabbit-spring-boot-example')
include('the-white-rabbit-vertx-example')
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.viartemev.thewhiterabbit.example

import com.rabbitmq.client.ConnectionFactory
import com.rabbitmq.client.MessageProperties
import com.viartemev.thewhiterabbit.channel.confirmChannel
import com.viartemev.thewhiterabbit.channel.publish
import com.viartemev.thewhiterabbit.publisher.OutboundMessage
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.runBlocking

val EXCHANGE_NAME = ""
val QUEUE_NAME = "test_queue"
val times = 100_000

fun main() {
val connectionFactory = ConnectionFactory().apply { useNio() }
val connection = connectionFactory.newConnection()
runBlocking {
connection.confirmChannel {
publish {
coroutineScope {
val messages = (1..times).map { createMessage("") }
publishWithConfirmAsync(this.coroutineContext, messages).awaitAll()
}
}
}
}
connection.close()
}

private fun createMessage(body: String) =
OutboundMessage(EXCHANGE_NAME, QUEUE_NAME, MessageProperties.PERSISTENT_BASIC, body)
14 changes: 14 additions & 0 deletions the-white-rabbit-example/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>

<root level="DEBUG">
<appender-ref ref="STDOUT"/>
</root>

</configuration>

0 comments on commit 8159742

Please sign in to comment.