Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NATS Unable to to Connect #4234

Open
jordanperrin opened this issue Aug 2, 2023 · 0 comments
Open

NATS Unable to to Connect #4234

jordanperrin opened this issue Aug 2, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@jordanperrin
Copy link

Describe the bug
I am running a NATS-streaming docker container and I am trying to get IBM FHIR docker to connect to it. In my config file I have the following:
NOTE: "test-cluster" is the correct and default clusterID for NATS-streaming , TLS is disabled on the NATS container, anf both containers are bridged on the same network.

"nats": {
                "enabled": true,
                "cluster": "test-cluster",
                "channel": "fhirNotifications",
                "clientId": "ibm-fhir",
                "servers": "nats://0.0.0.0:4222",
                "useTLS": false,
                "truststoreLocation": "resources/security/nats.client.truststore.jks",
                "truststorePassword": "change-password",
                "keystoreLocation": "resources/security/nats.client.keystore.jks",
                "keystorePassword": "change-password"
            }

The error stack trace from the IBM FHIR Server:

[8/2/23, 13:59:08:062 UTC] 00000036 FHIRNotificat E   Caught exception while initializing NATS publisher.
         java.io.IOException: Unable to connect to NATS servers: nats://0.0.0.0:4222
        at io.nats.client.impl.NatsConnection.connect(NatsConnection.java:207)
        at io.nats.client.impl.NatsImpl.createConnection(NatsImpl.java:29)
        at io.nats.client.Nats.createConnection(Nats.java:276)
        at io.nats.client.Nats.connect(Nats.java:193)
        at com.ibm.fhir.server.notifications.nats.FHIRNotificationNATSPublisher.init(FHIRNotificationNATSPublisher.java:103)
        at com.ibm.fhir.server.notifications.nats.FHIRNotificationNATSPublisher.<init>(FHIRNotificationNATSPublisher.java:54)
        at com.ibm.fhir.server.listener.FHIRServletContextListener.contextInitialized(FHIRServletContextListener.java:213)
        at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2447)
        at com.ibm.ws.webcontainer31.osgi.webapp.WebApp31.notifyServletContextCreated(WebApp31.java:517)
        at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1045)
        at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6685)
        at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:472)
        at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApplication(DynamicVirtualHost.java:467)
        at com.ibm.ws.webcontainer.osgi.WebContainer.startWebApplication(WebContainer.java:1188)
        at com.ibm.ws.webcontainer.osgi.WebContainer.startModule(WebContainer.java:977)
        at com.ibm.ws.app.manager.module.internal.ModuleHandlerBase.deployModule(ModuleHandlerBase.java:99)
        at com.ibm.ws.app.manager.module.internal.DeployedModuleInfoImpl.installModule(DeployedModuleInfoImpl.java:49)
        at com.ibm.ws.app.manager.module.internal.SimpleDeployedAppInfoBase.deployModules(SimpleDeployedAppInfoBase.java:597)
        at com.ibm.ws.app.manager.module.internal.SimpleDeployedAppInfoBase.installApp(SimpleDeployedAppInfoBase.java:511)
        at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:349)
        at com.ibm.ws.app.manager.war.internal.WARApplicationHandlerImpl.install(WARApplicationHandlerImpl.java:65)
        at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:161)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1357)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:901)
        at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:245)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:866)
[8/2/23, 13:59:08:066 UTC] 00000036 FHIRServletCo E   Encountered an exception while initializing the servlet context.
                                 java.lang.IllegalStateException: Caught exception while initializing NATS publisher.
        at com.ibm.fhir.server.notifications.nats.FHIRNotificationNATSPublisher.init(FHIRNotificationNATSPublisher.java:125)
        at com.ibm.fhir.server.notifications.nats.FHIRNotificationNATSPublisher.<init>(FHIRNotificationNATSPublisher.java:54)
        at com.ibm.fhir.server.listener.FHIRServletContextListener.contextInitialized(FHIRServletContextListener.java:213)
        at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2447)
        at com.ibm.ws.webcontainer31.osgi.webapp.WebApp31.notifyServletContextCreated(WebApp31.java:517)
        at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1045)
        at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6685)
        at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:472)
        at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApplication(DynamicVirtualHost.java:467)
        at com.ibm.ws.webcontainer.osgi.WebContainer.startWebApplication(WebContainer.java:1188)
        at com.ibm.ws.webcontainer.osgi.WebContainer.startModule(WebContainer.java:977)
        at com.ibm.ws.app.manager.module.internal.ModuleHandlerBase.deployModule(ModuleHandlerBase.java:99)
        at com.ibm.ws.app.manager.module.internal.DeployedModuleInfoImpl.installModule(DeployedModuleInfoImpl.java:49)
        at com.ibm.ws.app.manager.module.internal.SimpleDeployedAppInfoBase.deployModules(SimpleDeployedAppInfoBase.java:597)
        at com.ibm.ws.app.manager.module.internal.SimpleDeployedAppInfoBase.installApp(SimpleDeployedAppInfoBase.java:511)
        at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:349)
        at com.ibm.ws.app.manager.war.internal.WARApplicationHandlerImpl.install(WARApplicationHandlerImpl.java:65)
        at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:161)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1357)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:901)
        at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:245)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:866)
Caused by: java.io.IOException: Unable to connect to NATS servers: nats://0.0.0.0:4222
        at io.nats.client.impl.NatsConnection.connect(NatsConnection.java:207)
        at io.nats.client.impl.NatsImpl.createConnection(NatsImpl.java:29)
        at io.nats.client.Nats.createConnection(Nats.java:276)
        at io.nats.client.Nats.connect(Nats.java:193)
        at com.ibm.fhir.server.notifications.nats.FHIRNotificationNATSPublisher.init(FHIRNotificationNATSPublisher.java:103)
        ... 23 more
[8/2/23, 13:59:08:185 UTC] 00000036 IncidentImpl  I   FFDC1015I: An FFDC Incident has been created: "java.lang.RuntimeException: Encountered an exception while initializing the servlet context. com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated 1341" at ffdc_23.08.02_13.59.08.0.log
[8/2/23, 13:59:08:187 UTC] 00000036 webapp        E com.ibm.ws.webcontainer.webapp.WebApp notifyServletContextCreated SRVE0283E: Exception caught while initializing context: java.lang.RuntimeException: Encountered an exception while initializing the servlet context.
        at com.ibm.fhir.server.listener.FHIRServletContextListener.contextInitialized(FHIRServletContextListener.java:249)
        at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2447)
        at com.ibm.ws.webcontainer31.osgi.webapp.WebApp31.notifyServletContextCreated(WebApp31.java:517)
        at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1045)
        at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6685)
        at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:472)
        at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApplication(DynamicVirtualHost.java:467)
        at com.ibm.ws.webcontainer.osgi.WebContainer.startWebApplication(WebContainer.java:1188)
        at com.ibm.ws.webcontainer.osgi.WebContainer.startModule(WebContainer.java:977)
        at com.ibm.ws.app.manager.module.internal.ModuleHandlerBase.deployModule(ModuleHandlerBase.java:99)
        at com.ibm.ws.app.manager.module.internal.DeployedModuleInfoImpl.installModule(DeployedModuleInfoImpl.java:49)
        at com.ibm.ws.app.manager.module.internal.SimpleDeployedAppInfoBase.deployModules(SimpleDeployedAppInfoBase.java:597)
        at com.ibm.ws.app.manager.module.internal.SimpleDeployedAppInfoBase.installApp(SimpleDeployedAppInfoBase.java:511)
        at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:349)
        at com.ibm.ws.app.manager.war.internal.WARApplicationHandlerImpl.install(WARApplicationHandlerImpl.java:65)
        at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:161)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1357)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:901)
        at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:245)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:866)
Caused by: java.lang.IllegalStateException: Caught exception while initializing NATS publisher.
        at com.ibm.fhir.server.notifications.nats.FHIRNotificationNATSPublisher.init(FHIRNotificationNATSPublisher.java:125)
        at com.ibm.fhir.server.notifications.nats.FHIRNotificationNATSPublisher.<init>(FHIRNotificationNATSPublisher.java:54)
        at com.ibm.fhir.server.listener.FHIRServletContextListener.contextInitialized(FHIRServletContextListener.java:213)
        ... 21 more
Caused by: java.io.IOException: Unable to connect to NATS servers: nats://0.0.0.0:4222
        at io.nats.client.impl.NatsConnection.connect(NatsConnection.java:207)
        at io.nats.client.impl.NatsImpl.createConnection(NatsImpl.java:29)
        at io.nats.client.Nats.createConnection(Nats.java:276)
        at io.nats.client.Nats.connect(Nats.java:193)
        at com.ibm.fhir.server.notifications.nats.FHIRNotificationNATSPublisher.init(FHIRNotificationNATSPublisher.java:103)
        ... 23 more

I created my own java application and replicated the code from FHIRNotificationNATSPublisher and the code works successfully on my java app. The code that I have running successfully:

String servers = "nats://0.0.0.0:4222";
io.nats.client.Options.Builder builder = new io.nats.client.Options.Builder();	
builder.maxReconnects(-1);
builder.connectionName("fhirNotifications");
builder.servers(servers.split(","));
io.nats.client.Options natsOptions = builder.build();
Connection nc = Nats.connect(natsOptions);      
Options streamingOptions = new Options.Builder().natsConn(nc).build();      
StreamingConnection sc = NatsStreaming.connect("test-cluster", "JAVA-APP-TEST", streamingOptions);

Environment
Which version of LinuxForHealth FHIR Server?
Latest Docker Image

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error
@jordanperrin jordanperrin added the bug Something isn't working label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant