Class BasicNatsConnection

All Implemented Interfaces:
AdaptrisComponent, AdaptrisConnection, ComponentLifecycle, ComponentLifecycleExtension, StateManagedComponent

@ComponentProfile(summary="Basic connection to a NATS server", tag="nats.io, nats", since="3.9.3") public class BasicNatsConnection extends NatsConnection
Basic Connection to a NATS server.

This connection assumes that Nats#connect(String) is sufficient configuration for connecting to your NATS server (i.e. everything you need is configurable via the URL). Generally put your 'closest' NATS server as the URL, since it will discover other servers after it initially connects and use those as required.

Configuring any kind of ConnectionErrorHandler has no effect on this type of connection, as we will be relying on the automatic reconnection that happens behind the seens from the NATS core java client. By default outgoing messages will be buffered in memory; pending reconnection and subsequent redelivery.

In the adapter configuration file this class is aliased as nats-server-basic-connection which is the preferred alternative to the fully qualified classname when building your configuration.

  • Constructor Details

    • BasicNatsConnection

      public BasicNatsConnection()
  • Method Details

    • prepareConnection

      protected void prepareConnection() throws CoreException
      Overrides:
      prepareConnection in class NatsConnection
      Throws:
      CoreException
    • connect

      protected io.nats.client.Connection connect() throws Exception
      Specified by:
      connect in class NatsConnection
      Throws:
      Exception
    • withUrl

      public <T extends BasicNatsConnection> T withUrl(String u)
    • connectionName

      protected String connectionName()
      Specified by:
      connectionName in class NatsConnection
    • getUrl

      public String getUrl()
      The URL to the nats server assuming that Nats#connect(String) is sufficient configuration for connecting to your NATS server.

      The Java client generally expects URLs of the form nats://hostname:port but has support for the additional forms (it can be a list that is comma separated):

      • nats://user:pass@hostname:port
      • nats://token@hostname:port
      • opentls://hostname:port which will use TLS but accept "any certificates"
      • tls://hostname:port which will use TLS using the default SSL Context and may require client certificates
    • setUrl

      public void setUrl(String url)
      The URL to the nats server assuming that Nats#connect(String) is sufficient configuration for connecting to your NATS server.

      The Java client generally expects URLs of the form nats://hostname:port but has support for the additional forms (it can be a list that is comma separated):

      • nats://user:pass@hostname:port
      • nats://token@hostname:port
      • opentls://hostname:port which will use TLS but accept "any certificates"
      • tls://hostname:port which will use TLS using the default SSL Context and may require client certificates