File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
runtime/src/main/java/io/quarkiverse/reactive/messaging/nats/jetstream/client/connection Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 44
55import java .util .concurrent .atomic .AtomicReference ;
66
7+ import jakarta .annotation .PostConstruct ;
78import jakarta .annotation .PreDestroy ;
89import jakarta .enterprise .context .ApplicationScoped ;
910import jakarta .enterprise .inject .Produces ;
@@ -23,6 +24,16 @@ public class ConnectionFactoryImpl implements ConnectionFactory {
2324 private final TlsContext tlsContext ;
2425 private final AtomicReference <Connection > connection = new AtomicReference <>();
2526
27+ @ PostConstruct
28+ void init () {
29+ // Force TLS context resolution on CDI/main thread to avoid CDI lookups from worker threads
30+ try {
31+ tlsContext .sslContext ();
32+ } catch (Exception e ) {
33+ log .warn ("Failed to eagerly initialize TLS context" , e );
34+ }
35+ }
36+
2637 @ Produces
2738 @ Override
2839 public Connection create () {
Original file line number Diff line number Diff line change 22
33import java .util .Optional ;
44
5+ import jakarta .annotation .PostConstruct ;
56import jakarta .enterprise .context .ApplicationScoped ;
67import jakarta .enterprise .inject .Produces ;
78
1718public class TlsContextFactoryImpl implements TlsContextFactory {
1819 private final ConnectorConfiguration configuration ;
1920 private final TlsConfigurationRegistry registry ;
21+ private volatile TlsContext cached ;
2022
21- @ Produces
22- @ Override
23- public TlsContext create () {
23+ @ PostConstruct
24+ void init () {
2425 try {
2526 if (configuration .connection ().sslEnabled ().orElse (false )) {
2627 final var tlsConfiguration = configuration .connection ().tlsConfigurationName ()
2728 .flatMap (registry ::get )
2829 .orElseGet (this ::getDefaultTlsConfiguration );
29- return new TlsContextImpl (Optional .of (tlsConfiguration .createSSLContext ()));
30+ cached = new TlsContextImpl (Optional .of (tlsConfiguration .createSSLContext ()));
3031 } else {
31- return new TlsContextImpl (Optional .empty ());
32+ cached = new TlsContextImpl (Optional .empty ());
3233 }
3334 } catch (Exception e ) {
3435 throw new RuntimeException (e );
3536 }
3637 }
3738
39+ @ Produces
40+ @ Override
41+ public TlsContext create () {
42+ return cached ;
43+ }
44+
3845 private TlsConfiguration getDefaultTlsConfiguration () {
3946 return registry .getDefault ().orElseThrow (
4047 () -> new IllegalStateException ("No Quarkus TLS configuration found for NATS JetStream connection" ));
You can’t perform that action at this time.
0 commit comments