org.mbari.oni.etc.nats

Members list

Type members

Classlikes

class NatsBridge(sink: NatsMessage => Unit, source: Option[String] = ...) extends AutoCloseable

Translates ChangeEvents published on the ChangeBus into NatsMessages and forwards them to the sink. Only changes to concept data made by this instance are forwarded: see ChangeEvent.affectsConceptData. Remote events (learned from other instances) are never forwarded, otherwise instances would echo each other's messages forever.

Translates ChangeEvents published on the ChangeBus into NatsMessages and forwards them to the sink. Only changes to concept data made by this instance are forwarded: see ChangeEvent.affectsConceptData. Remote events (learned from other instances) are never forwarded, otherwise instances would echo each other's messages forever.

Value parameters

sink

Receives the messages, typically NatsPublisher.offer

source

Stamped on each message so receivers can ignore their own messages

Attributes

Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any
object NatsClient

Creates NATS connections that reconnect forever.

Creates NATS connections that reconnect forever.

Careful: Nats.connectReconnectOnConnect retries until it connects. With unlimited reconnects it never returns if the server is down, so it must never be called on Oni's startup thread. Use connectInBackground, which is what lets Oni start (and keep working) when NATS is unavailable.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
NatsClient.type
final case class NatsConfig(url: String, enable: Boolean, topic: String)

Configuration for NATS from application.conf/reference.conf

Configuration for NATS from application.conf/reference.conf

Value parameters

enable

true if NATS should be used

topic

the NATS topic to publish to

url

e.g. nats://localhost:4222

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object NatsMessage

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class NatsMessage(action: String, dataType: String, id: Option[String] = ..., source: Option[String] = ...)

A minimal message describing a committed change. It is used to tell other services that something changed so they can refresh (e.g. invalidate a cache) without sending the entire record. The receiving service queries Oni for the current state.

A minimal message describing a committed change. It is used to tell other services that something changed so they can refresh (e.g. invalidate a cache) without sending the entire record. The receiving service queries Oni for the current state.

Value parameters

action

1 of CREATED, UPDATED, or DELETED

dataType

The kind of record that changed, e.g. CONCEPT, CONCEPT_NAME, LINK_REALIZATION

id

The primary key of the changed record. None if many records changed (e.g. a bulk rename of link targets).

source

Identifies the Oni instance that sent the message, so that an instance can ignore its own messages.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object NatsPublisher

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
class NatsPublisher(val url: String, val topic: String, maxQueueSize: Int = ...) extends AutoCloseable

Publishes NatsMessages to a NATS topic. Messages are queued and sent from a daemon thread so that a slow or unavailable NATS server never blocks the thread that committed a database transaction. Messages that arrive close together are de-duplicated. The initial connection is made on a background thread, and the jnats client reconnects automatically (forever) after that, so Oni starts normally even if NATS is down. Messages offered before the connection exists wait in the queue.

Publishes NatsMessages to a NATS topic. Messages are queued and sent from a daemon thread so that a slow or unavailable NATS server never blocks the thread that committed a database transaction. Messages that arrive close together are de-duplicated. The initial connection is made on a background thread, and the jnats client reconnects automatically (forever) after that, so Oni starts normally even if NATS is down. Messages offered before the connection exists wait in the queue.

Messages only signal that something changed, and consumers re-query Oni, so if the queue overflows during a long outage the newest message is dropped rather than blocking or growing memory without bound.

Attributes

Companion
object
Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
class NatsSubscriber(val url: String, val topic: String, instanceId: String = ...) extends AutoCloseable

Listens to the NATS topic for changes made by other Oni instances and republishes them on the local ChangeBus as remote events, so things like the KnowledgebaseCache are cleared on this instance too. Messages sent by this instance (identified by instanceId) are ignored since the change has already been handled locally.

Listens to the NATS topic for changes made by other Oni instances and republishes them on the local ChangeBus as remote events, so things like the KnowledgebaseCache are cleared on this instance too. Messages sent by this instance (identified by instanceId) are ignored since the change has already been handled locally.

Messages sent while this instance is disconnected from NATS are lost, so we also publish a catch-all remote event whenever the connection is (re)established. That clears caches that may have missed changes.

The connection is made on a background thread, so creating a subscriber never blocks (or fails) if NATS is down. It starts listening as soon as NATS is available. See awaitReady.

Value parameters

instanceId

Messages with this source are ignored. Only overridden in tests, to simulate another instance.

Attributes

Companion
object
Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any