Skip to content

Commit b250af0

Browse files
committed
initial commit
0 parents  commit b250af0

11 files changed

Lines changed: 544 additions & 0 deletions

File tree

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Kotlin template
3+
# Compiled class file
4+
*.class
5+
6+
# Log file
7+
*.log
8+
9+
# BlueJ files
10+
*.ctxt
11+
12+
# Mobile Tools for Java (J2ME)
13+
.mtj.tmp/
14+
15+
# Package Files #
16+
*.jar
17+
*.war
18+
*.nar
19+
*.ear
20+
*.zip
21+
*.tar.gz
22+
*.rar
23+
24+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
25+
hs_err_pid*
26+
27+
### Gradle template
28+
.gradle
29+
/build/
30+
31+
# Ignore Gradle GUI config
32+
gradle-app.setting
33+
34+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
35+
!gradle-wrapper.jar
36+
37+
# Cache of project
38+
.gradletasknamecache
39+
40+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
41+
# gradle/wrapper/gradle-wrapper.properties
42+
43+
.idea

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Postgres Notify Flowable
2+
3+
Consume Postgres LISTEN/NOTIFY messages in your JVM applications using RxJava, and the standard Postgres JDBC driver.
4+
5+
- Enables RxJava's rich API for asynchronous processing
6+
- Requires only a single database connection for as many subscribers as you want
7+
- Uses standard Postgres JDBC driver
8+
- Minimizes polling overhead by centralizing it
9+
10+
## About
11+
12+
The Postgres JDBC driver has built in support for retrieving LISTEN/NOTIFY messages. The provided API is functional and basic. This code is an adapter from this basic API to RxJava to allow for a much richer asynchronous API.
13+
14+
Further, Postgres requires a dedicated connection to call LISTEN on. One has to be careful not to be too wasteful with database connections. This code enables you to ergonomically share a single such connection for multiple usages in your application by making use of the reactive extensions `share()` functionality.
15+
16+
The idea is that you create a single `PostgresNotifyFlowable`, providing it all channels you would like to LISTEN on, and then you can subscribe to this `Flowable` as many times as you want sharing a single database connection across your application.
17+
18+
The standard Postgres JDBC driver API is built around polling to retrieve LISTEN/NOTIFY messages. This might be wasteful in some scenarios, but at the same time one might not want to forgo the advantages of using the standard driver over a non-standard non-polling based one. This code helps you minimize the overhead by making it simple to have centralized polling over a single connection.
19+
20+
## How to Use
21+
22+
```
23+
val channels = PostgresNotifyFlowable.forChannels(
24+
jdbcUrl = db.jdbcUrl,
25+
user = db.username,
26+
password = db.password,
27+
channels = listOf("hello"))
28+
29+
channels
30+
.filter({ it.name == "test" })
31+
.subscribe({ notification: PGNotification ->
32+
33+
})
34+
```

build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
3+
}
4+
5+
group 'ayedo'
6+
version '1.0.0'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
14+
implementation 'org.slf4j:slf4j-api:1.7.25'
15+
implementation 'org.postgresql:postgresql:42.2.8'
16+
implementation 'io.reactivex.rxjava2:rxjava:2.2.13'
17+
implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
18+
19+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
20+
testImplementation 'org.assertj:assertj-core:3.12.2'
21+
testImplementation 'org.testcontainers:testcontainers:1.12.3'
22+
testImplementation "org.testcontainers:junit-jupiter:1.12.3"
23+
testImplementation "org.testcontainers:postgresql:1.12.3"
24+
25+
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
26+
testRuntime 'org.slf4j:slf4j-simple:1.7.25'
27+
}
28+
29+
test {
30+
useJUnitPlatform()
31+
}
32+
33+
compileKotlin {
34+
kotlinOptions.jvmTarget = "1.8"
35+
}
36+
compileTestKotlin {
37+
kotlinOptions.jvmTarget = "1.8"
38+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kotlin.code.style=official

gradle/wrapper/gradle-wrapper.jar

53.9 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sat Nov 02 10:31:30 CET 2019
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
3+
distributionBase=GRADLE_USER_HOME
4+
distributionPath=wrapper/dists
5+
zipStorePath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'notifyflowable'
2+

0 commit comments

Comments
 (0)