connector
The Connector is the most fundamental construct of the framework, providing key capabilities to Microbus microservices:
- Startup and shutdown with corresponding callbacks
- Service hostname and a random instance ID, both used to address the microservice
- Subscription registration for the microservice’s endpoints, including
sub.Manual()for subscriptions that should not auto-activate at startup,sub.Tag(...)for grouping related subscriptions, andActivateSubscription/DeactivateSubscriptionto drive the manual lifecycle - Connectivity to NATS
- HTTP-like communication over NATS, unicast (request/response) and multicast (pub/sub)
- Structured logging
- Configuration
- Tickers to execute jobs on a recurring basis
- Distributed cache
- Embedded resource files and strings
- Distributed tracing
- Authorization
The connector package includes a separate source file for each functional area of the microservice. All these source files implement the same Connector class.
config.gois responsible for fetching config values from the configurator core microserviceconnector.godefines theConnectorstruct and provides a few getters and setterscontrol.godeals with subscribing and handling the control messages on the reserved port:888fragment.goorchestrates the fragmentation and defragmentation of large requests and responseslifecycle.goimplements theStartupandShutdownlogic, as well asGoandParallelfor running code in goroutineslogger.goprovides the structured logger for the microservice, fanning records out to the deployment’s console handler and, when configured, an OpenTelemetry logs exportermetrics.gocollects metrics with OpenTelemetrymuffler.gois an OpenTelemetry span sampler that excludes noisy spansotel.goresolves the OTLP endpoint, protocol and resource, and shares one reference-counted OTLP connection across the traces, metrics and logs signalspublish.godeals with outbound messagingres.gomanages the loading of files and localized strings from a resourceFSselectiveprocessor.gois an OpenTelemetry processor of tracing spans that exports only spans that are explicitly selectedsubjects.gocrafts the NATS subjects (topics) that a microservice subscribes to or publishes tosubscribe.godeals with inbound message handlingtime.gointroduces tickers to the microservicetracer.gosupports distributed tracing with OpenTelemetry