35
35
import org .bson .codecs .pojo .Conventions ;
36
36
import org .bson .codecs .pojo .PojoCodecProvider ;
37
37
import org .bson .codecs .pojo .PropertyCodecProvider ;
38
+ import org .slf4j .Logger ;
39
+ import org .slf4j .LoggerFactory ;
38
40
39
41
import com .mongodb .AuthenticationMechanism ;
40
42
import com .mongodb .Block ;
51
53
import com .mongodb .connection .ClusterConnectionMode ;
52
54
import com .mongodb .connection .ClusterSettings ;
53
55
import com .mongodb .connection .ConnectionPoolSettings ;
56
+ import com .mongodb .connection .NettyTransportSettings ;
54
57
import com .mongodb .connection .ServerSettings ;
55
58
import com .mongodb .connection .SocketSettings ;
56
59
import com .mongodb .connection .SslSettings ;
57
60
import com .mongodb .event .CommandListener ;
58
61
import com .mongodb .event .ConnectionPoolListener ;
59
62
import com .mongodb .reactivestreams .client .ReactiveContextProvider ;
60
63
64
+ import io .netty .channel .socket .SocketChannel ;
61
65
import io .quarkus .credentials .CredentialsProvider ;
62
66
import io .quarkus .credentials .runtime .CredentialsProviderFinder ;
63
67
import io .quarkus .mongodb .MongoClientName ;
64
68
import io .quarkus .mongodb .impl .ReactiveMongoClientImpl ;
65
69
import io .quarkus .mongodb .reactive .ReactiveMongoClient ;
70
+ import io .vertx .core .Vertx ;
71
+ import io .vertx .core .buffer .impl .VertxByteBufAllocator ;
66
72
67
73
/**
68
74
* This class is sort of a producer for {@link MongoClient} and {@link ReactiveMongoClient}.
@@ -86,20 +92,23 @@ public class MongoClients {
86
92
private final Map <String , ReactiveMongoClient > reactiveMongoClients = new HashMap <>();
87
93
private final Instance <ReactiveContextProvider > reactiveContextProviders ;
88
94
private final Instance <MongoClientCustomizer > customizers ;
95
+ private final Vertx vertx ;
89
96
90
97
public MongoClients (MongodbConfig mongodbConfig , MongoClientSupport mongoClientSupport ,
91
98
Instance <CodecProvider > codecProviders ,
92
99
Instance <PropertyCodecProvider > propertyCodecProviders ,
93
100
Instance <CommandListener > commandListeners ,
94
101
Instance <ReactiveContextProvider > reactiveContextProviders ,
95
- @ Any Instance <MongoClientCustomizer > customizers ) {
102
+ @ Any Instance <MongoClientCustomizer > customizers ,
103
+ Vertx vertx ) {
96
104
this .mongodbConfig = mongodbConfig ;
97
105
this .mongoClientSupport = mongoClientSupport ;
98
106
this .codecProviders = codecProviders ;
99
107
this .propertyCodecProviders = propertyCodecProviders ;
100
108
this .commandListeners = commandListeners ;
101
109
this .reactiveContextProviders = reactiveContextProviders ;
102
110
this .customizers = customizers ;
111
+ this .vertx = vertx ;
103
112
104
113
try {
105
114
//JDK bug workaround
@@ -255,6 +264,14 @@ private MongoClientSettings createMongoConfiguration(String name, MongoClientCon
255
264
MongoClientSettings .Builder settings = MongoClientSettings .builder ();
256
265
257
266
if (isReactive ) {
267
+ // we supports just NIO for now
268
+ if (!vertx .isNativeTransportEnabled ()) {
269
+ var nettyStreaming = NettyTransportSettings .nettyBuilder ()
270
+ .allocator (VertxByteBufAllocator .POOLED_ALLOCATOR )
271
+ .eventLoopGroup (vertx .nettyEventLoopGroup ())
272
+ .socketChannelClass (SocketChannel .class ).build ();
273
+ settings .transportSettings (nettyStreaming );
274
+ }
258
275
reactiveContextProviders .stream ().findAny ().ifPresent (settings ::contextProvider );
259
276
}
260
277
0 commit comments