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 Detail

      • NatsConnectionFromProperties

        public NatsConnectionFromProperties()
    • Method Detail

      • connect

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

        protected static java.lang.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