Files
LocalAI/core/services/messaging/interfaces.go
T
Ettore Di Giacinto 730d259976 chore(distributed): take the nats-io modules out of the build
Distributed mode has not dialled a message broker since the control plane
moved onto the workers' own outward tunnels and every fan-out family moved
onto PostgreSQL LISTEN/NOTIFY. What was left was the dependency itself, and
the code that existed only to feed it.

Dropped from go.mod: nats-io/jwt/v2, nats-io/nats.go, nats-io/nkeys,
nats-io/nuid and testcontainers-go/modules/nats, along with the fourteen
indirect requires that only the NATS testcontainer pulled in. go.sum carries
no nats line either, so the removal is not the partial kind where the require
goes and the checksum stays.

Deleted with them: pkg/natsauth in full, the broker client's remaining
options and TLS files, the per-node JWT minting on both the register and the
approve path, and the natsauth.Config parameter threaded through the node
routes. The credential manager is renamed and stripped rather than deleted,
because it still holds the tunnel token that every re-registration rotates.

The bus flags stay accepted and ignored, and are now hidden, on every command
that had them, so an existing unit file, compose file or Helm values file
still starts on the day of the upgrade. What is not kept is the validation
that REQUIRED one: a distributed frontend started with no bus URL is no
longer fatal. The TLS paths lose type:"existingfile" deliberately, so a
certificate deleted along with the broker cannot fail a startup.

One operator-visible behaviour change: --nats-require-auth no longer makes an
agent worker wait through admin approval. Ask for that wait with
--distributed-require-auth, which already implied it. It is documented in the
migration section and pinned from both sides.

A deployment now needs PostgreSQL and the frontends' own HTTP listener, and
nothing else.

coverage-baseline.txt moves from 54.2 to 62.0.

Assisted-by: Claude Opus 5 [claude-code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2026-09-05 03:27:17 +00:00

49 lines
2.2 KiB
Go

package messaging
// Publisher publishes JSON-encoded messages to broadcast subjects.
type Publisher interface {
Publish(subject string, data any) error
}
// Subscription represents a subscription that can be unsubscribed.
type Subscription interface {
Unsubscribe() error
}
// Broadcaster is the whole messaging surface: a publish reaches every
// subscriber on every replica.
//
// There is no second interface. Request/reply became a control RPC on the
// worker's tunnel, queue groups became a claim queue on the job store, and what
// is left is fan-out, which is one method more than Publisher. The wider
// MessagingClient that used to sit here is deleted rather than shrunk: two
// exported names for one method set in one package is an invitation for the
// next author to pick whichever the surrounding file already imported.
//
// IsConnected and Close are deliberately NOT here, and their absence is stated
// rather than left to be inferred.
//
// IsConnected has no production consumer. It is asserted by specs and read by
// logging, and a carrier's consumers must not branch on it. "The carrier is
// down" is not one of the four conditions a node's state can be in, and no code
// may turn it into evidence that a worker is absent.
//
// Close DOES have real callers, and they hold a CONCRETE type rather than this
// interface, which is why the interface can omit it.
type Broadcaster interface {
Publisher
Subscribe(subject string, handler func([]byte)) (Subscription, error)
}
// Broadcaster has one implementation a deployment runs on, *pgbus.Bus, and it
// cannot be named here, because pgbus imports this package. The conformance
// assertion lives in interfaces_test.go alongside the test double's, which is
// also where the method-set pin lives: a conformance assertion stays true
// however many methods grow back, so it cannot say that the retired halves are
// gone.
//
// The NATS client that used to be asserted on this line is deleted. There is no
// second carrier: the last family that needed one, agent.<name>.cancel, is a
// control verb on the agent worker's own tunnel, and no component of a
// distributed deployment opens a connection to a message broker.