Skip to content

Commit 8f607f5

Browse files
author
Michael Freeman
committed
Updating to use context
1 parent 2eafbcb commit 8f607f5

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ type Client struct {
3232
type messageHandler func(context.Context, jetstream.Msg) error
3333

3434
// Connect establishes a connection to NATS and sets up JetStream.
35-
func (c *Client) Connect() error {
35+
func (c *Client) Connect(ctx context.Context) error {
3636
if err := c.validateAndPrepare(); err != nil {
3737
return err
3838
}
3939

4040
connManager := NewConnectionManager(c.Config, c.logger, c.natsConnector, c.jetStreamCreator)
41-
if err := connManager.Connect(); err != nil {
41+
if err := connManager.Connect(ctx); err != nil {
4242
c.logger.Errorf("failed to connect to NATS server at %v: %v", c.Config.Server, err)
4343
return err
4444
}

connection_manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func NewConnectionManager(
8282
}
8383

8484
// Connect establishes a connection to NATS and sets up JetStream.
85-
func (cm *ConnectionManager) Connect() error {
85+
func (cm *ConnectionManager) Connect(ctx context.Context) error {
8686
cm.logger.Logf("Connecting to NATS server at %v", cm.config.Server)
8787

8888
opts := []nats.Option{nats.Name("GoFr NATS JetStreamClient")}

interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type JetStreamClient interface {
4242

4343
// ConnectionManagerInterface represents the main Client connection.
4444
type ConnectionManagerInterface interface {
45-
Connect() error
45+
Connect(ctx context.Context) error
4646
Close(ctx context.Context)
4747
Publish(ctx context.Context, subject string, message []byte, metrics Metrics) error
4848
Health() datasource.Health

pubsub_wrapper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ func (w *PubSubWrapper) Health() datasource.Health {
4444
}
4545

4646
// Connect establishes a connection to NATS.
47-
func (w *PubSubWrapper) Connect() error {
47+
func (w *PubSubWrapper) Connect(ctx context.Context) error {
4848
if w.Client.connManager != nil && w.Client.connManager.Health().Status == datasource.StatusUp {
4949
w.Client.logger.Log("NATS connection already established")
5050

5151
return nil
5252
}
5353

54-
err := w.Client.Connect()
54+
err := w.Client.Connect(ctx)
5555
if err != nil {
5656
w.Client.logger.Errorf("PubSubWrapper: Error connecting to NATS: %v", err)
5757
return err

0 commit comments

Comments
 (0)