51
51
import com .mongodb .connection .ClusterConnectionMode ;
52
52
import com .mongodb .connection .ClusterSettings ;
53
53
import com .mongodb .connection .ConnectionPoolSettings ;
54
+ import com .mongodb .connection .NettyTransportSettings ;
54
55
import com .mongodb .connection .ServerSettings ;
55
56
import com .mongodb .connection .SocketSettings ;
56
57
import com .mongodb .connection .SslSettings ;
57
58
import com .mongodb .event .CommandListener ;
58
59
import com .mongodb .event .ConnectionPoolListener ;
59
60
import com .mongodb .reactivestreams .client .ReactiveContextProvider ;
60
61
62
+ import io .netty .channel .socket .SocketChannel ;
61
63
import io .quarkus .credentials .CredentialsProvider ;
62
64
import io .quarkus .credentials .runtime .CredentialsProviderFinder ;
63
65
import io .quarkus .mongodb .MongoClientName ;
64
66
import io .quarkus .mongodb .impl .ReactiveMongoClientImpl ;
65
67
import io .quarkus .mongodb .reactive .ReactiveMongoClient ;
68
+ import io .vertx .core .Vertx ;
69
+ import io .vertx .core .buffer .impl .VertxByteBufAllocator ;
66
70
67
71
/**
68
72
* This class is sort of a producer for {@link MongoClient} and {@link ReactiveMongoClient}.
@@ -86,20 +90,23 @@ public class MongoClients {
86
90
private final Map <String , ReactiveMongoClient > reactiveMongoClients = new HashMap <>();
87
91
private final Instance <ReactiveContextProvider > reactiveContextProviders ;
88
92
private final Instance <MongoClientCustomizer > customizers ;
93
+ private final Vertx vertx ;
89
94
90
95
public MongoClients (MongodbConfig mongodbConfig , MongoClientSupport mongoClientSupport ,
91
96
Instance <CodecProvider > codecProviders ,
92
97
Instance <PropertyCodecProvider > propertyCodecProviders ,
93
98
Instance <CommandListener > commandListeners ,
94
99
Instance <ReactiveContextProvider > reactiveContextProviders ,
95
- @ Any Instance <MongoClientCustomizer > customizers ) {
100
+ @ Any Instance <MongoClientCustomizer > customizers ,
101
+ Vertx vertx ) {
96
102
this .mongodbConfig = mongodbConfig ;
97
103
this .mongoClientSupport = mongoClientSupport ;
98
104
this .codecProviders = codecProviders ;
99
105
this .propertyCodecProviders = propertyCodecProviders ;
100
106
this .commandListeners = commandListeners ;
101
107
this .reactiveContextProviders = reactiveContextProviders ;
102
108
this .customizers = customizers ;
109
+ this .vertx = vertx ;
103
110
104
111
try {
105
112
//JDK bug workaround
@@ -255,6 +262,14 @@ private MongoClientSettings createMongoConfiguration(String name, MongoClientCon
255
262
MongoClientSettings .Builder settings = MongoClientSettings .builder ();
256
263
257
264
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
+ }
258
273
reactiveContextProviders .stream ().findAny ().ifPresent (settings ::contextProvider );
259
274
}
260
275
0 commit comments