Skip to content

Commit f5ddb7d

Browse files
committed
fix: nats connection
1 parent 97b6132 commit f5ddb7d

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

pkg/apis/batch/v1/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type ExecAction struct {
105105
}
106106

107107
type Retry struct {
108-
Attempts int `json:"attempts"`
108+
Attempts int `json:"attempts,omitempty"`
109109
// Delay is the time in seconds to wait between retries
110110
Delay int `json:"delay"`
111111
}
@@ -164,13 +164,13 @@ func (p PubSubConfig) String() string {
164164

165165
// +kubebuilder:object:generate=true
166166
type NATSConfig struct {
167-
URL `json:",inline"`
167+
URL string `json:"url,omitempty"`
168168
Subject string `json:"subject"`
169-
Queue string `json:"queue"`
169+
Queue string `json:"queue,omitempty"`
170170
}
171171

172172
func (n NATSConfig) String() string {
173-
return fmt.Sprintf("nats://%s", n.Queue)
173+
return fmt.Sprintf("nats://%s", n.Subject)
174174
}
175175

176176
// +kubebuilder:object:generate=true

pkg/types.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"github.com/aws/aws-sdk-go-v2/service/sqs"
88
"github.com/flanksource/commons/logger"
99
"github.com/flanksource/duty/context"
10+
"github.com/nats-io/nats.go"
1011
"gocloud.dev/pubsub"
1112
"gocloud.dev/pubsub/awssnssqs"
1213
"gocloud.dev/pubsub/kafkapubsub"
14+
"gocloud.dev/pubsub/natspubsub"
1315

1416
batchv1alpha1 "github.com/flanksource/batch-runner/pkg/apis/batch/v1"
1517
)
@@ -63,7 +65,14 @@ func Subscribe(ctx context.Context, c *batchv1alpha1.Config) (*pubsub.Subscripti
6365
}
6466

6567
if c.NATS != nil {
66-
return pubsub.OpenSubscription(ctx, fmt.Sprintf("nats://%s", c.NATS.Queue))
68+
conn, err := nats.Connect(c.NATS.URL)
69+
if err != nil {
70+
return nil, err
71+
}
72+
73+
return natspubsub.OpenSubscriptionV2(conn, c.NATS.Subject, &natspubsub.SubscriptionOptions{
74+
Queue: c.NATS.Queue,
75+
})
6776
}
6877

6978
if c.Memory != nil {

0 commit comments

Comments
 (0)