Skip to content

Commit c89b42b

Browse files
committed
feat: customize the RabbitMQ connection
1 parent 98b9a2b commit c89b42b

File tree

20 files changed

+152
-44
lines changed

20 files changed

+152
-44
lines changed

async/async-commons/src/main/java/org/reactivecommons/async/commons/DiscardNotifier.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.reactivecommons.async.commons.communications.Message;
44
import reactor.core.publisher.Mono;
55

6+
@FunctionalInterface
67
public interface DiscardNotifier {
78
Mono<Void> notifyDiscard(Message message);
89
}

async/async-commons/src/main/java/org/reactivecommons/async/commons/utils/matcher/Matcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Set;
44

5+
@FunctionalInterface
56
public interface Matcher {
67
String match(Set<String> sources, String target);
78
}

docs/docs/migration-guides.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ sidebar_position: 4
66

77
## From 5.x.x to 6.x.x
88

9+
### New Features
10+
11+
- **Connection customization:** You can now customize the RabbitMQ connection by defining a
12+
`ConnectionFactoryCustomizer` bean. For more details,
13+
see [Customizing the connection](/reactive-commons-java/docs/reactive-commons/configuration_properties/rabbitmq#customizing-the-connection).
14+
15+
```java title="Programmatic configuration"
16+
17+
@Bean
18+
public ConnectionFactoryCustomizer connectionFactoryCustomizer() {
19+
return (ConnectionFactoryCustomizer) (asyncProps, connectionFactory) -> {
20+
connectionFactory.setExceptionHandler(new MyCustomExceptionHandler()); // Optional custom exception handler
21+
connectionFactory.setCredentialsProvider(new MyCustomCredentialsProvider()); // Optional custom credentials provider
22+
return connectionFactory;
23+
};
24+
}
25+
```
26+
927
### Change notes
1028

1129
- The configuration property `listenReplies` for RabbitMQ now defaults to `null`. Previously, it was `true`, causing all
@@ -25,7 +43,6 @@ app:
2543
```
2644
2745
```java title="Programmatic configuration"
28-
2946
@Configuration
3047
public class MyDomainConfig {
3148

@@ -56,7 +73,6 @@ app:
5673
```
5774

5875
```java title="Programmatic configuration"
59-
6076
@Configuration
6177
public class MyDomainConfig {
6278

@@ -78,7 +94,8 @@ public class MyDomainConfig {
7894

7995
### New Features
8096

81-
- Support for multiple brokers: It is now possible to configure and connect to up to two brokers simultaneously, using
97+
- **Support for multiple brokers:** It is now possible to configure and connect to up to two brokers simultaneously,
98+
using
8299
independent domains in the configuration.
83100

84101
### Change notes
@@ -118,7 +135,6 @@ app:
118135
Before: the connection was defined manually in a Java class, as shown below:
119136
120137
```java
121-
122138
@Log4j2
123139
@Configuration
124140
@RequiredArgsConstructor
@@ -180,7 +196,6 @@ app:
180196
Domains can also be configured programmatically:
181197
182198
```java title="Programmatic configuration"
183-
184199
@Configuration
185200
public class MyDomainConfig {
186201

docs/docs/reactive-commons/configuration_properties/1-rabbitmq.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ app:
2020
listenReplies: null # Allows true or false values. If you're using the ReqReply pattern, set it to true. If you don't, set it to false.
2121
createTopology: true # if your organization have restrictions with automatic topology creation you can set it to false and create it manually or by your organization process.
2222
delayedCommands: false # Enable to send a delayed command to an external target
23-
prefetchCount: 250 # is the maximum number of in flight messages you can reduce it to process less concurrent messages, this settings acts per instance of your service
23+
prefetchCount: 250 # is the maximum number of in flight messages you can reduce it to process less concurrent messages, this setting acts per instance of your service
2424
useDiscardNotifierPerDomain: false # if true it uses a discard notifier for each domain,when false it uses a single discard notifier for all domains with default 'app' domain
2525
enabled: true # if you want to disable this domain you can set it to false
2626
mandatory: false # if you want to enable mandatory messages, you can set it to true, this will throw an exception if the message cannot be routed to any queue
@@ -168,7 +168,7 @@ import java.lang.reflect.GenericArrayType;
168168
169169
@Log4j2
170170
@Configuration
171-
public class AsyncEventBusConfig {
171+
public class RabbitMQConfig {
172172
173173
// TODO: You should create the GenericManager bean as indicated in Secrets Manager library
174174
@Bean
@@ -188,10 +188,27 @@ public class AsyncEventBusConfig {
188188
return genericManager.getSecret(secretName, RabbitConnectionProperties.class).toRabbitProperties();
189189
}
190190
}
191+
```
192+
193+
## Customizing the connection
191194

195+
For advanced control over the RabbitMQ connection, you can define a `ConnectionFactoryCustomizer` bean. This allows you
196+
to configure options that are not exposed through standard properties, such as custom timeouts, SSL/TLS settings,
197+
or automatic recovery strategies:
198+
199+
```java
200+
201+
@Bean
202+
public ConnectionFactoryCustomizer connectionFactoryCustomizer() {
203+
return (ConnectionFactoryCustomizer) (asyncProps, connectionFactory) -> {
204+
connectionFactory.setExceptionHandler(new MyCustomExceptionHandler()); // Optional custom exception handler
205+
connectionFactory.setCredentialsProvider(new MyCustomCredentialsProvider()); // Optional custom credentials provider
206+
return connectionFactory;
207+
};
208+
}
192209
```
193210

194-
## Connections and Channels
211+
## Connections and channels
195212

196213
Reactive Commons establishes **a single connection to the RabbitMQ broker**, which is reused for all messaging
197214
operations, both sending and listening. However, the number of open **channels** within that connection varies depending
@@ -201,7 +218,7 @@ shows how the number of channels changes according to the applied configuration.
201218
In the context of this documentation, a domain refers to a connection with a broker. The configuration supports up to
202219
two brokers, which means the described scenarios are limited to a maximum of two domains.
203220

204-
### Annotations Used in the Tables
221+
### Annotations used in the tables
205222

206223
**[1] Annotations for sending messages:**
207224

gradle/wrapper/gradle-wrapper.jar

1.65 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
3+
distributionSha256Sum=a17ddd85a26b6a7f5ddb71ff8b05fc5104c0202c6e64782429790c933686c806
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
45
networkTimeout=10000
56
validateDistributionUrl=true
67
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
#
4-
# Copyright © 2015-2021 the original authors.
4+
# Copyright © 2015 the original authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -114,7 +114,6 @@ case "$( uname )" in #(
114114
NONSTOP* ) nonstop=true ;;
115115
esac
116116

117-
CLASSPATH="\\\"\\\""
118117

119118

120119
# Determine the Java command to use to start the JVM.
@@ -172,7 +171,6 @@ fi
172171
# For Cygwin or MSYS, switch paths to Windows format before running java
173172
if "$cygwin" || "$msys" ; then
174173
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
175-
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
176174

177175
JAVACMD=$( cygpath --unix "$JAVACMD" )
178176

@@ -212,7 +210,6 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
212210

213211
set -- \
214212
"-Dorg.gradle.appname=$APP_BASE_NAME" \
215-
-classpath "$CLASSPATH" \
216213
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217214
"$@"
218215

gradlew.bat

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ goto fail
7070
:execute
7171
@rem Setup the command line
7272

73-
set CLASSPATH=
7473

7574

7675
@rem Execute Gradle
77-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
76+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
7877

7978
:end
8079
@rem End local scope for the variables with windows NT shell

main.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ allprojects {
33
apply plugin: 'jacoco'
44

55
java {
6-
sourceCompatibility = JavaVersion.VERSION_17
7-
targetCompatibility = JavaVersion.VERSION_17
6+
toolchain {
7+
languageVersion = JavaLanguageVersion.of(17)
8+
}
89
}
910

1011
repositories {
@@ -182,5 +183,7 @@ tasks.register('generateMergedReport', JacocoReport) {
182183
}
183184

184185
tasks.named('wrapper') {
185-
gradleVersion = '8.14.3'
186+
gradleVersion = '9.1.0'
187+
validateDistributionUrl = true
188+
distributionSha256Sum = "a17ddd85a26b6a7f5ddb71ff8b05fc5104c0202c6e64782429790c933686c806"
186189
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
dependencies {
22
implementation 'org.springframework.boot:spring-boot-starter'
3+
}
4+
5+
test {
6+
// Disable error when no tests are found (for example modules)
7+
failOnNoDiscoveredTests = false
38
}

0 commit comments

Comments
 (0)