Skip to content

Commit 3b46c20

Browse files
authored
Add reactive-streams Notifier implementation with optional Reactor support (#263)
* Add reactive-streams Notifier implementation with optional Project Reactor support. * Rollbar java reactivestreams implementation: Replace Thread.sleep in ReactorAsyncHttpClient with Project Reactor built-in block method.
1 parent 2a86ba7 commit 3b46c20

File tree

56 files changed

+4580
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4580
-551
lines changed

.palantir/revapi.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
acceptedBreaks:
2+
"1.7.6":
3+
com.rollbar:rollbar-java:
4+
- code: "java.field.removed"
5+
old: "field com.rollbar.notifier.config.ConfigBuilder.defaultErrorLevel"
6+
justification: "Removing protected fields, deriving from ConfigBuilder should\
7+
\ be done by other SDK classes only"
8+
- code: "java.field.removed"
9+
old: "field com.rollbar.notifier.config.ConfigBuilder.defaultMessageLevel"
10+
justification: "Removing protected fields, deriving from ConfigBuilder should\
11+
\ be done by other SDK classes only"
12+
- code: "java.field.removed"
13+
old: "field com.rollbar.notifier.config.ConfigBuilder.defaultThrowableLevel"
14+
justification: "Removing protected fields, deriving from ConfigBuilder should\
15+
\ be done by other SDK classes only"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ For actual usage, the easiest way to get started is by looking at the examples:
2626
- [rollbar-logback](https://github.com/rollbar/rollbar-java/tree/master/examples/rollbar-logback)
2727
- [rollbar-spring-webmvc](https://github.com/rollbar/rollbar-java/tree/master/examples/rollbar-spring-webmvc)
2828
- [rollbar-spring-boot-webmvc](https://github.com/rollbar/rollbar-java/tree/master/examples/rollbar-spring-boot-webmvc)
29+
- [rollbar-reactive-streams-reactor](https://github.com/rollbar/rollbar-java/tree/master/examples/rollbar-reactive-streams-reactor)
2930

3031
## Release History & Changelog
3132

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ subprojects { project ->
3535
!project.parent.name.equals("examples") &&
3636
!project.name.contains('examples')) {
3737
apply plugin: 'java-library'
38-
apply from: "$rootDir/gradle/release.gradle"
38+
39+
// reactive-streams support will be published along with Spring Webflux
40+
if (!project.name.startsWith('rollbar-reactive-streams')) {
41+
apply from: "$rootDir/gradle/release.gradle"
42+
}
3943

4044
apply from: "$rootDir/gradle/quality.gradle"
4145

@@ -57,7 +61,7 @@ subprojects { project ->
5761
dependencies {
5862
testImplementation group: 'junit', name: 'junit', version: '4.12'
5963
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
60-
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.28.2'
64+
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.8.0'
6165
}
6266

6367
compileJava {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apply plugin: 'application'
2+
3+
jar {
4+
archivesBaseName = "rollbar-reactive-streams-reactor-example"
5+
archiveVersion = '0.1.0'
6+
}
7+
8+
application {
9+
mainClassName = "com.rollbar.reactivestreams.reactor.example.Application"
10+
}
11+
12+
dependencies {
13+
implementation project(":rollbar-reactive-streams-reactor")
14+
15+
implementation platform('io.projectreactor:reactor-bom:2020.0.6')
16+
implementation 'io.projectreactor:reactor-core'
17+
implementation 'io.projectreactor:reactor-tools'
18+
implementation 'io.projectreactor.netty:reactor-netty-http'
19+
20+
implementation 'org.slf4j:slf4j-log4j12:1.7.25'
21+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.rollbar.reactivestreams.reactor.example;
2+
3+
import com.rollbar.reactivestreams.notifier.ReactorRollbar;
4+
import com.rollbar.reactivestreams.notifier.config.Config;
5+
import com.rollbar.reactivestreams.notifier.config.ConfigBuilder;
6+
import com.rollbar.reactivestreams.notifier.sender.http.ReactorAsyncHttpClient;
7+
import reactor.core.publisher.Hooks;
8+
import reactor.core.publisher.Mono;
9+
import reactor.netty.DisposableChannel;
10+
import reactor.netty.DisposableServer;
11+
import reactor.netty.http.client.HttpClient;
12+
import reactor.netty.http.client.HttpClientResponse;
13+
import reactor.netty.tcp.TcpServer;
14+
15+
/**
16+
* Application example using rollbar-reactive-streams-reactor.
17+
*/
18+
public class Application {
19+
/**
20+
* Main method for the rollbar-reactive-streams-reactor example application.
21+
*
22+
* @param args command line arguments (unused).
23+
*/
24+
public static void main(String[] args) throws Exception {
25+
Config config = ConfigBuilder
26+
.withAccessToken(System.getenv("ROLLBAR_ACCESSTOKEN"))
27+
.httpClient(new ReactorAsyncHttpClient.Builder().build())
28+
.environment("development")
29+
.build();
30+
31+
ReactorRollbar rollbar = new ReactorRollbar(config);
32+
33+
// We'll create a misbehaving HTTP server that immediately disconnects clients
34+
DisposableServer badServer = TcpServer.create().port(0)
35+
.doOnConnection(DisposableChannel::disposeNow)
36+
.bindNow();
37+
38+
String url = "http://localhost:" + badServer.port();
39+
40+
// Rollbar.logMonoError will log the error and return the original Mono
41+
Mono<HttpClientResponse> request = HttpClient.create()
42+
.get()
43+
.uri(url)
44+
.response()
45+
.onErrorResume(rollbar::logMonoError);
46+
47+
// The Mono still contains the original error, and we're free to handle it however we see fit.
48+
// For this example, we'll replace the error it with an empty Mono to let the application
49+
// exit successfully, and block until it completes.
50+
request.onErrorResume(r -> Mono.empty()).block();
51+
52+
rollbar.close(true);
53+
54+
badServer.dispose();
55+
}
56+
57+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Root logger option
2+
log4j.rootLogger=INFO, stdout
3+
4+
# Rollbar logger
5+
log4j.logger.com.rollbar.notifier=DEBUG, stdout
6+
log4j.additivity.com.rollbar.notifier=false
7+
log4j.logger.com.rollbar.reactivestreams.notifier=DEBUG, stdout
8+
log4j.additivity.com.rollbar.reactivestreams.notifier=false
9+
10+
# Direct log messages to stdout
11+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
12+
log4j.appender.stdout.Target=System.out
13+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
14+
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

gradle/quality.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ spotbugsMain {
3131
}
3232
}
3333
spotbugsTest {
34-
ignoreFailures = true
34+
enabled = false
3535
}
3636

3737
afterEvaluate {
3838
if (project.tasks.findByPath("spotbugsIntegTest") != null) {
3939
spotbugsIntegTest {
40-
ignoreFailures = true
40+
enabled = false
4141
}
4242
}
4343
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.rollbar.api.annotations;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
7+
/**
8+
* <p>
9+
* Classes and methods annotated with {@link Unstable} will likely change in ways that will break
10+
* backwards compatibility, both at source and binary level.
11+
* </p>
12+
*/
13+
@Retention(RetentionPolicy.RUNTIME)
14+
@Documented
15+
public @interface Unstable {
16+
String reason = "This class or method is not part of the SDK's public API, and will likely "
17+
+ "change in ways that will break backwards compatibility, both at source and binary level.";
18+
}

rollbar-java/build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ buildscript {
1111

1212
apply plugin: "nebula.integtest"
1313

14+
configurations {
15+
integTestArtifacts
16+
}
17+
1418
dependencies {
1519
api project(':rollbar-api')
1620

@@ -76,3 +80,13 @@ test {
7680
// running tests.
7781
systemProperty 'ROLLBAR_IMPLEMENTATION_VERSION', VERSION_NAME
7882
}
83+
84+
// The 'java-test-fixtures' plugin is not getting along with 'nebula.integtest', so we'll use this instead
85+
task integTestJar(type: Jar, dependsOn: project.tasks.integTestClasses) {
86+
archiveClassifier.set('integtest')
87+
from sourceSets.integTest.output
88+
}
89+
90+
artifacts {
91+
integTestArtifacts integTestJar
92+
}

0 commit comments

Comments
 (0)