-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
69 lines (59 loc) · 2.27 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package nats
import (
"context"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
"gofr.dev/pkg/gofr/datasource"
"gofr.dev/pkg/gofr/datasource/pubsub"
)
//go:generate mockgen -destination=mock_client.go -package=nats -source=./interfaces.go Client,Subscription,ConnInterface,ConnectionManagerInterface,SubscriptionManagerInterface,StreamManagerInterface
// ConnInterface represents the main Client connection.
type ConnInterface interface {
Status() nats.Status
Close()
NATSConn() *nats.Conn
JetStream() (jetstream.JetStream, error)
}
// NATSConnector represents the main Client connection.
type NATSConnector interface {
Connect(string, ...nats.Option) (ConnInterface, error)
}
// JetStreamCreator represents the main Client JetStream Client.
type JetStreamCreator interface {
New(conn ConnInterface) (jetstream.JetStream, error)
}
// JetStreamClient represents the main Client JetStream Client.
type JetStreamClient interface {
Publish(ctx context.Context, subject string, message []byte) error
Subscribe(ctx context.Context, subject string, handler messageHandler) error
Close(ctx context.Context) error
DeleteStream(ctx context.Context, name string) error
CreateStream(ctx context.Context, cfg StreamConfig) error
CreateOrUpdateStream(ctx context.Context, cfg jetstream.StreamConfig) (jetstream.Stream, error)
Health() datasource.Health
}
// ConnectionManagerInterface represents the main Client connection.
type ConnectionManagerInterface interface {
Connect(ctx context.Context) error
Close(ctx context.Context)
Publish(ctx context.Context, subject string, message []byte, metrics Metrics) error
Health() datasource.Health
JetStream() (jetstream.JetStream, error)
}
// SubscriptionManagerInterface represents the main Subscription Manager.
type SubscriptionManagerInterface interface {
Subscribe(
ctx context.Context,
topic string,
js jetstream.JetStream,
cfg *Config,
logger pubsub.Logger,
metrics Metrics) (*pubsub.Message, error)
Close()
}
// StreamManagerInterface represents the main Stream Manager.
type StreamManagerInterface interface {
CreateStream(ctx context.Context, cfg StreamConfig) error
DeleteStream(ctx context.Context, name string) error
CreateOrUpdateStream(ctx context.Context, cfg *jetstream.StreamConfig) (jetstream.Stream, error)
}