Class NatsConnectionFromProperties

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

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

Uses io.nats.client#Options#Builder() to build the connection via the properties; no validation of properties is done, we just convert the configuration into properties and pass it into the Builder object.

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.

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

  • Constructor Details

    • NatsConnectionFromProperties

      public NatsConnectionFromProperties()
  • 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
    • withConnectionProperties

      public <T extends NatsConnectionFromProperties> T withConnectionProperties(KeyValuePairSet p)
    • connectionName

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

      protected static String findConnectionName(KeyValuePairSet p)
    • getConnectionProperties

      public KeyValuePairSet getConnectionProperties()
      The connection properties.

      You will probably need to refer to the NATS.io documentation to figure out the available properties; they will be passed in as-is to new Options.Builder(Properties) with no verification. Generally the configuration properties will start with io.nats.client. but may change between releases.

      For instance if you wanted to control the URL / Username + Password then you might have

           
           io.nats.client.url=nats://localhost:1234
           io.nats.client.username=MyUsername
           io.nats.client.password=MyPassword
           io.nats.client.verbose=true
           
       

    • setConnectionProperties

      public void setConnectionProperties(KeyValuePairSet connectionProperties)
      The connection properties.

      You will probably need to refer to the NATS.io documentation to figure out the available properties; they will be passed in as-is to new Options.Builder(Properties) with no verification. Generally the configuration properties will start with io.nats.client. but may change between releases.

      For instance if you wanted to control the URL / Username + Password then you might have

           
           io.nats.client.url=nats://localhost:1234
           io.nats.client.username=MyUsername
           io.nats.client.password=MyPassword
           io.nats.client.verbose=true