Skip to content

Commit 16f9ef8

Browse files
committed
Mongo reactive client should use Netty transport
1 parent 22d8b35 commit 16f9ef8

File tree

1 file changed

+16
-1
lines changed
  • extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,22 @@
5151
import com.mongodb.connection.ClusterConnectionMode;
5252
import com.mongodb.connection.ClusterSettings;
5353
import com.mongodb.connection.ConnectionPoolSettings;
54+
import com.mongodb.connection.NettyTransportSettings;
5455
import com.mongodb.connection.ServerSettings;
5556
import com.mongodb.connection.SocketSettings;
5657
import com.mongodb.connection.SslSettings;
5758
import com.mongodb.event.CommandListener;
5859
import com.mongodb.event.ConnectionPoolListener;
5960
import com.mongodb.reactivestreams.client.ReactiveContextProvider;
6061

62+
import io.netty.channel.socket.SocketChannel;
6163
import io.quarkus.credentials.CredentialsProvider;
6264
import io.quarkus.credentials.runtime.CredentialsProviderFinder;
6365
import io.quarkus.mongodb.MongoClientName;
6466
import io.quarkus.mongodb.impl.ReactiveMongoClientImpl;
6567
import io.quarkus.mongodb.reactive.ReactiveMongoClient;
68+
import io.vertx.core.Vertx;
69+
import io.vertx.core.buffer.impl.VertxByteBufAllocator;
6670

6771
/**
6872
* This class is sort of a producer for {@link MongoClient} and {@link ReactiveMongoClient}.
@@ -86,20 +90,23 @@ public class MongoClients {
8690
private final Map<String, ReactiveMongoClient> reactiveMongoClients = new HashMap<>();
8791
private final Instance<ReactiveContextProvider> reactiveContextProviders;
8892
private final Instance<MongoClientCustomizer> customizers;
93+
private final Vertx vertx;
8994

9095
public MongoClients(MongodbConfig mongodbConfig, MongoClientSupport mongoClientSupport,
9196
Instance<CodecProvider> codecProviders,
9297
Instance<PropertyCodecProvider> propertyCodecProviders,
9398
Instance<CommandListener> commandListeners,
9499
Instance<ReactiveContextProvider> reactiveContextProviders,
95-
@Any Instance<MongoClientCustomizer> customizers) {
100+
@Any Instance<MongoClientCustomizer> customizers,
101+
Vertx vertx) {
96102
this.mongodbConfig = mongodbConfig;
97103
this.mongoClientSupport = mongoClientSupport;
98104
this.codecProviders = codecProviders;
99105
this.propertyCodecProviders = propertyCodecProviders;
100106
this.commandListeners = commandListeners;
101107
this.reactiveContextProviders = reactiveContextProviders;
102108
this.customizers = customizers;
109+
this.vertx = vertx;
103110

104111
try {
105112
//JDK bug workaround
@@ -255,6 +262,14 @@ private MongoClientSettings createMongoConfiguration(String name, MongoClientCon
255262
MongoClientSettings.Builder settings = MongoClientSettings.builder();
256263

257264
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(SocketChannel.class).build();
271+
settings.transportSettings(nettyStreaming);
272+
}
258273
reactiveContextProviders.stream().findAny().ifPresent(settings::contextProvider);
259274
}
260275

0 commit comments

Comments
 (0)