-
Notifications
You must be signed in to change notification settings - Fork 124
Add NATS producer #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NATS producer #377
Conversation
Add a NATS publisher implementation and corresponding tests. * **config/config.go** - Add NATS configuration struct to the Config struct. - Add NATS configuration to the ConfigureProducers method. * **datastore/nats/nats.go** - Implement Producer struct for NATS. - Implement NewProducer function to initialize NATS producer. - Implement Produce method to send messages to NATS. - Implement Close method to close NATS connection. - Implement ProcessReliableAck method to handle reliable acknowledgements. - Implement ReportError method to report errors. * **datastore/nats/nats_test.go** - Implement unit tests for NewProducer function. - Implement unit tests for Produce method. - Implement unit tests for Close method. - Implement unit tests for ProcessReliableAck method. - Implement unit tests for ReportError method. * **.devcontainer/devcontainer.json** - Add devcontainer configuration for building the project. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Teslemetry/tesla-fleet-telemetry?shareId=XXXX-XXXX-XXXX-XXXX).
* Add `nats.go` dependency to `go.mod` * Add `nats.go`, `nkeys`, `nuid`, `compress`, `crypto`, `sync`, and `text` dependencies to `go.sum`
* Add import for `github.com/teslamotors/fleet-telemetry/metrics/adapter` * Add tests for error handling, metrics, and different payload types in `TestProduce` * Fix references to `metricsRegistry` fields to use exported fields * Remove unused import for `context` Update `.devcontainer/devcontainer.json` * Add "test" task with command "make test"
This reverts commit 1ab5c27.
This reverts commit 5c1ce35.
datastore/nats/nats.go
Outdated
| func NewProducer(config *Config, namespace string, prometheusEnabled bool, metricsCollector metrics.MetricCollector, airbrakeHandler *airbrake.Handler, ackChan chan (*telemetry.Record), reliableAckTxTypes map[string]interface{}, logger *logrus.Logger) (telemetry.Producer, error) { | ||
| registerMetricsOnce(metricsCollector) | ||
|
|
||
| natsConn, err := NatsConnect(config.URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be a good idea to add some options:
nats.RetryOnFailedConnect(true),
nats.MaxReconnects(-1), // so that it will not stop reconnectingand potentially logging using
ClosedHandler
ErrorHandler
ConnectHandler
ReconnectErrHandler
DisconnectErrHandler
for visibility.
|
nice, I was also thinking about this, but was kinda busy. currently, I just use mqtt on NATS and then use a jetstream to persist the messages and move them to KV. |
I started with that but disliked the way the data was structured, and lost some of the other metadata. |
|
I use nats also and have a Tesla. |
Description
Adds a producer for NATS. I am using this in my environment so am sharing it back.
Fixes # (issue)
Type of change
Please select all options that apply to this change:
Checklist:
Confirm you have completed the following steps: