feat: scaffold agentmon services and k8s deploy
Adds Go microservices (ingest-gateway, event-processor, query-api, web-ui), NATS+Postgres wiring, initial schema/init job, ingress manifests for LAN+tailnet, and a multi-arch image build script.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package nats
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
gnats "github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
type Publisher struct {
|
||||
conn *gnats.Conn
|
||||
topic string
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func NewPublisher(url, topic string) (*Publisher, error) {
|
||||
conn, err := gnats.Connect(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Publisher{conn: conn, topic: topic, timeout: 5 * time.Second}, nil
|
||||
}
|
||||
|
||||
func (p *Publisher) Close() {
|
||||
p.conn.Close()
|
||||
}
|
||||
|
||||
func (p *Publisher) Publish(ctx context.Context, data []byte) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, p.timeout)
|
||||
defer cancel()
|
||||
|
||||
_ = ctx
|
||||
return p.conn.Publish(p.topic, data)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package nats
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gnats "github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
type Subscriber struct {
|
||||
conn *gnats.Conn
|
||||
sub *gnats.Subscription
|
||||
topic string
|
||||
}
|
||||
|
||||
func NewSubscriber(url, topic string) (*Subscriber, error) {
|
||||
conn, err := gnats.Connect(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Subscriber{conn: conn, topic: topic}, nil
|
||||
}
|
||||
|
||||
func (s *Subscriber) Close() {
|
||||
if s.sub != nil {
|
||||
_ = s.sub.Unsubscribe()
|
||||
}
|
||||
s.conn.Close()
|
||||
}
|
||||
|
||||
func (s *Subscriber) Subscribe(ctx context.Context, handler func(msg []byte) error) error {
|
||||
sub, err := s.conn.Subscribe(s.topic, func(m *gnats.Msg) {
|
||||
_ = handler(m.Data)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.sub = sub
|
||||
|
||||
<-ctx.Done()
|
||||
return ctx.Err()
|
||||
}
|
||||
Reference in New Issue
Block a user