Class NatsTransporter

All Implemented Interfaces:
io.nats.client.ConnectionListener, io.nats.client.MessageHandler, MetricConstants, MoleculerLifecycle

public class NatsTransporter extends Transporter implements io.nats.client.MessageHandler, io.nats.client.ConnectionListener
NATS Transporter. NATS Server is a simple, high performance open source messaging system for cloud native applications, IoT messaging, and microservices architectures (website: https://nats.io). Tested with NATS server version 1.3.0. Usage:
ServiceBroker broker = ServiceBroker.builder().nodeID("node1")
.transporter(new NatsTransporter("localhost")).build();
Required dependency:

// https://mvnrepository.com/artifact/io.nats/jnats
compile group: 'io.nats', name: 'jnats', version: '2.6.6'
See Also:
  • Field Details

    • username

      protected String username
      Username for basic authentication.
    • password

      protected String password
      Password for basic authentication.
    • secure

      protected boolean secure
      Use the default SSL Context, if it exists.
    • urls

      protected String[] urls
      Nats server url(s).
    • sslContext

      protected SSLContext sslContext
      Optional SSL Context.
    • noRandomize

      protected boolean noRandomize
      Turn off server pool randomization.
    • maxPingsOut

      protected int maxPingsOut
      Set the maximum number of pings the client can have in flight.
    • pingInterval

      protected long pingInterval
      Set the interval between attempts to pings the server in MILLISECONDS.
    • connectionTimeout

      protected long connectionTimeout
      Set the timeout for connection attempts in MILLISECONDS.
    • verbose

      protected boolean verbose
      Turn on verbose mode with the server.
    • bufferSize

      protected int bufferSize
      Sets the initial size for buffers in the connection.
    • authHandler

      protected io.nats.client.AuthHandler authHandler
      Optional AuthHandler.
    • noEcho

      protected boolean noEcho
      Turn off echo.
    • utf8Support

      protected boolean utf8Support
      Enable UTF8 channels.
    • pedantic

      protected boolean pedantic
      Turn on pedantic mode for the server.
    • advancedStats

      protected boolean advancedStats
      Turn on advanced stats, primarily for test/benchmarks.
    • opentls

      protected boolean opentls
      Set the SSL context to one that accepts any server certificate and has no client certificate.
    • oldRequestStyle

      protected boolean oldRequestStyle
      Turn on the old request style that uses a new inbox and subscriber for each request.
    • client

      protected io.nats.client.Connection client
    • dispatcher

      protected io.nats.client.Dispatcher dispatcher
    • started

      protected final AtomicBoolean started
  • Constructor Details

    • NatsTransporter

      public NatsTransporter()
    • NatsTransporter

      public NatsTransporter(String... urls)
    • NatsTransporter

      public NatsTransporter(String username, String password, boolean secure, String... urls)
  • Method Details

    • connect

      public void connect()
      Specified by:
      connect in class Transporter
    • connectionEvent

      public void connectionEvent(io.nats.client.Connection conn, io.nats.client.ConnectionListener.Events type)
      Specified by:
      connectionEvent in interface io.nats.client.ConnectionListener
    • disconnect

      protected void disconnect()
    • reconnect

      protected void reconnect()
    • error

      protected void error(Throwable cause)
      Description copied from class: Transporter
      Any I/O error occurred. Implementation-specific error handling goes here (reconnection, etc.).
      Overrides:
      error in class Transporter
      Parameters:
      cause - I/O error
    • stopped

      public void stopped()
      Closes transporter.
      Specified by:
      stopped in interface MoleculerLifecycle
      Overrides:
      stopped in class Transporter
    • subscribe

      public io.datatree.Promise subscribe(String channel)
      Specified by:
      subscribe in class Transporter
    • onMessage

      public void onMessage(io.nats.client.Message msg)
      Specified by:
      onMessage in interface io.nats.client.MessageHandler
    • publish

      public void publish(String channel, io.datatree.Tree message)
      Specified by:
      publish in class Transporter
    • getStatistics

      public io.nats.client.Statistics getStatistics()
      Returns:
      Statistics
    • getConnectionTimeout

      public long getConnectionTimeout()
      Returns:
      the connectionTimeout
    • setConnectionTimeout

      public void setConnectionTimeout(long connectionTimeout)
      Parameters:
      connectionTimeout - the connectionTimeout to set
    • getBufferSize

      public int getBufferSize()
      Returns:
      the bufferSize
    • setBufferSize

      public void setBufferSize(int bufferSize)
      Parameters:
      bufferSize - the bufferSize to set
    • getAuthHandler

      public io.nats.client.AuthHandler getAuthHandler()
      Returns:
      the authHandler
    • setAuthHandler

      public void setAuthHandler(io.nats.client.AuthHandler authHandler)
      Parameters:
      authHandler - the authHandler to set
    • isNoEcho

      public boolean isNoEcho()
      Returns:
      the noEcho
    • setNoEcho

      public void setNoEcho(boolean noEcho)
      Parameters:
      noEcho - the noEcho to set
    • isUtf8Support

      public boolean isUtf8Support()
      Returns:
      the utf8Support
    • setUtf8Support

      public void setUtf8Support(boolean utf8Support)
      Parameters:
      utf8Support - the utf8Support to set
    • isPedantic

      public boolean isPedantic()
      Returns:
      the pedantic
    • setPedantic

      public void setPedantic(boolean pedantic)
      Parameters:
      pedantic - the pedantic to set
    • isAdvancedStats

      public boolean isAdvancedStats()
      Returns:
      the advancedStats
    • setAdvancedStats

      public void setAdvancedStats(boolean advancedStats)
      Parameters:
      advancedStats - the advancedStats to set
    • isOpentls

      public boolean isOpentls()
      Returns:
      the opentls
    • setOpentls

      public void setOpentls(boolean opentls)
      Parameters:
      opentls - the opentls to set
    • getUsername

      public String getUsername()
      Returns:
      the username
    • setUsername

      public void setUsername(String username)
      Parameters:
      username - the username to set
    • getPassword

      public String getPassword()
      Returns:
      the password
    • setPassword

      public void setPassword(String password)
      Parameters:
      password - the password to set
    • isSecure

      public boolean isSecure()
      Returns:
      the secure
    • setSecure

      public void setSecure(boolean secure)
      Parameters:
      secure - the secure to set
    • getUrls

      public String[] getUrls()
      Returns:
      the urls
    • setUrls

      public void setUrls(String... urls)
      Parameters:
      urls - the urls to set
    • getSslContext

      public SSLContext getSslContext()
      Returns:
      the sslContext
    • setSslContext

      public void setSslContext(SSLContext sslContext)
      Parameters:
      sslContext - the sslContext to set
    • isNoRandomize

      public boolean isNoRandomize()
      Returns:
      the noRandomize
    • setNoRandomize

      public void setNoRandomize(boolean noRandomize)
      Parameters:
      noRandomize - the noRandomize to set
    • getMaxPingsOut

      public int getMaxPingsOut()
      Returns:
      the maxPingsOut
    • setMaxPingsOut

      public void setMaxPingsOut(int maxPingsOut)
      Parameters:
      maxPingsOut - the maxPingsOut to set
    • getPingInterval

      public long getPingInterval()
      Returns:
      the pingInterval
    • setPingInterval

      public void setPingInterval(long pingInterval)
      Parameters:
      pingInterval - the pingInterval to set
    • isVerbose

      public boolean isVerbose()
      Returns:
      the verbose
    • setVerbose

      public void setVerbose(boolean verbose)
      Parameters:
      verbose - the verbose to set
    • isOldRequestStyle

      public boolean isOldRequestStyle()
      Returns:
      the oldRequestStyle
    • setOldRequestStyle

      public void setOldRequestStyle(boolean oldRequestStyle)
      Parameters:
      oldRequestStyle - the oldRequestStyle to set