nats.java icon indicating copy to clipboard operation
nats.java copied to clipboard

Error: stan: connect request timeout StreamingConnection

Open jordanperrin opened this issue 1 year ago • 1 comments

Hello, I a running a nats docker container and I am using io.nats to connect to it. But when I try creating a StreamingConnection object I get stan: connect request timeout error. I looked at https://github.com/nats-io/stan.go/issues/285 and looked for the cluster id, however I see the nats container doesn't have a streaming module in the .conf file so I'm more or less at a dead-end. I tried using the nats-streaming docker but then I get this error:

Jul 31, 2023 5:16:04 PM io.nats.client.impl.ErrorListenerLoggerImpl exceptionOccurred SEVERE: exceptionOccurred, Exception: java.net.SocketTimeoutException: Connect timed out

Here is how I have my java code setup inside a static main method:

        String[] servers = {"nats://ruser:[email protected]:4222"};
	io.nats.client.Options.Builder builder = new io.nats.client.Options.Builder();
        builder.maxReconnects(-1);
        builder.connectionName("fhirNotifications");
        builder.servers(servers);
        io.nats.client.Options natsOptions = builder.build();
        Connection nc = Nats.connect(natsOptions);
        Options streamingOptions = new Options.Builder().natsConn(nc).build();
        StreamingConnection sc = NatsStreaming.connect("my_cluster", "ibm-fhir", streamingOptions);

I did not edit any of the config files just as a sidenote. If you can point in the right direction that would be very helpful, ty :)

jordanperrin avatar Jul 31 '23 21:07 jordanperrin

@jordanperrin Are you using the stan.java client (which connects to a STAN server) or the nats.java client (which connects to the NATS server)? What server are you trying to connect to, STAN or NATS? STAN is completely end of life and not supported, and nats.java does not connect to STAN, just NATS.

My recommendation is to get the latest NATS server and nats.java client.

NATS Server

JNATS nats.java

scottf avatar Feb 13 '24 14:02 scottf