bus.go 482 B

1234567891011121314151617181920212223
  1. package borealis
  2. import (
  3. "fmt"
  4. "github.com/nats-io/nats.go"
  5. )
  6. type Bus struct {
  7. NATS *nats.EncodedConn
  8. }
  9. func Connect(url string) (*Bus, error) {
  10. conn, err := nats.Connect(url)
  11. if err != nil {
  12. return nil, fmt.Errorf("failed to connect to the broker: %w", err)
  13. }
  14. encodedConn, err := nats.NewEncodedConn(conn, nats.JSON_ENCODER) // TODO
  15. if err != nil {
  16. return nil, fmt.Errorf("failed to configure the bus encoding: %w", err)
  17. }
  18. return &Bus{NATS: encodedConn}, nil
  19. }