Skip to content

Commit 46d4274

Browse files
committed
Add config option defaulted to true
1 parent 3b101c0 commit 46d4274

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClientConfig.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,21 @@ public interface MongoClientConfig {
190190
*/
191191
Optional<UuidRepresentation> uuidRepresentation();
192192

193+
enum TransportConfig {
194+
/**
195+
* Uses a Netty-based transport re-using the existing Netty event loops.
196+
*/
197+
NETTY,
198+
/**
199+
* Uses an asynchronous transport running async I/O tasks on a dedicated thread pool owned by the driver.
200+
*/
201+
ASYNC
202+
}
203+
204+
/**
205+
* Configures the transport.
206+
*/
207+
@WithDefault("netty")
208+
TransportConfig transport();
209+
193210
}

extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClients.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
import com.mongodb.connection.ClusterConnectionMode;
5252
import com.mongodb.connection.ClusterSettings;
5353
import com.mongodb.connection.ConnectionPoolSettings;
54-
import com.mongodb.connection.NettyTransportSettings;
5554
import com.mongodb.connection.ServerSettings;
5655
import com.mongodb.connection.SocketSettings;
5756
import com.mongodb.connection.SslSettings;
57+
import com.mongodb.connection.TransportSettings;
5858
import com.mongodb.event.CommandListener;
5959
import com.mongodb.event.ConnectionPoolListener;
6060
import com.mongodb.reactivestreams.client.ReactiveContextProvider;
@@ -261,15 +261,19 @@ private MongoClientSettings createMongoConfiguration(String name, MongoClientCon
261261

262262
MongoClientSettings.Builder settings = MongoClientSettings.builder();
263263

264+
switch (config.transport()) {
265+
case NETTY:
266+
// we supports just NIO for now
267+
if (!vertx.isNativeTransportEnabled()) {
268+
configureNettyTransport(settings);
269+
}
270+
break;
271+
case ASYNC:
272+
// no-op since this is the default behaviour
273+
break;
274+
}
275+
264276
if (isReactive) {
265-
// we supports just NIO for now
266-
if (!vertx.isNativeTransportEnabled()) {
267-
var nettyStreaming = NettyTransportSettings.nettyBuilder()
268-
.allocator(VertxByteBufAllocator.POOLED_ALLOCATOR)
269-
.eventLoopGroup(vertx.nettyEventLoopGroup())
270-
.socketChannelClass(NioSocketChannel.class).build();
271-
settings.transportSettings(nettyStreaming);
272-
}
273277
reactiveContextProviders.stream().findAny().ifPresent(settings::contextProvider);
274278
}
275279

@@ -344,6 +348,14 @@ private MongoClientSettings createMongoConfiguration(String name, MongoClientCon
344348
return settings.build();
345349
}
346350

351+
private void configureNettyTransport(MongoClientSettings.Builder settings) {
352+
var nettyStreaming = TransportSettings.nettyBuilder()
353+
.allocator(VertxByteBufAllocator.POOLED_ALLOCATOR)
354+
.eventLoopGroup(vertx.nettyEventLoopGroup())
355+
.socketChannelClass(NioSocketChannel.class).build();
356+
settings.transportSettings(nettyStreaming);
357+
}
358+
347359
private boolean doesNotHaveClientNameQualifier(Bean<?> bean) {
348360
for (Annotation qualifier : bean.getQualifiers()) {
349361
if (qualifier.annotationType().equals(MongoClientName.class)) {

0 commit comments

Comments
 (0)