Skip to content

Commit

Permalink
docs cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
roblaszczak committed Oct 20, 2024
1 parent dd3e97a commit 7249cb8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 45 deletions.
4 changes: 2 additions & 2 deletions sns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type PublisherConfig struct {
// DoNotCreateTopicIfNotExists disables creating the topic if it does not exist.
DoNotCreateTopicIfNotExists bool

// TopicResolver is a function that resolves the topic name to the topic ARN.
// TopicResolver is a function that resolves the Watermill topic name to the topic ARN.
TopicResolver TopicResolver

// GenerateCreateTopicInput generates the input for the CreateTopic operation.
Expand Down Expand Up @@ -78,7 +78,7 @@ type SubscriberConfig struct {
// OptFns are options for the SNS client.
OptFns []func(*sns.Options)

// TopicResolver is a function that resolves the topic name to the topic ARN.
// TopicResolver is a function that resolves the Watermill topic name to the topic ARN.
TopicResolver TopicResolver

// GenerateSqsQueueName generates the name of the SQS queue for the SNS subscription.
Expand Down
3 changes: 3 additions & 0 deletions sns/topic.go → sns/url_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type TopicResolver interface {
}

// TransparentTopicResolver is a TopicResolver that passes the topic as is.
// You should use SNS topic ARN as in Subscribe and Publish.
type TransparentTopicResolver struct{}

func (a TransparentTopicResolver) ResolveTopic(ctx context.Context, topic string) (snsTopic TopicArn, err error) {
Expand All @@ -21,6 +22,8 @@ func (a TransparentTopicResolver) ResolveTopic(ctx context.Context, topic string

// GenerateArnTopicResolver is a TopicResolver that generates ARN for the topic
// using the provided account ID and region.
//
// You should use this resolver if you want to pass only the topic name to Subscribe and Publish.
type GenerateArnTopicResolver struct {
accountID string
region string
Expand Down
87 changes: 44 additions & 43 deletions sqs/url_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,6 @@ import (
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
)

// QueueUrlResolver resolves queue URL by topic passed to Publisher.Publish, Subscriber.Subscribe.
type QueueUrlResolver interface {
ResolveQueueUrl(ctx context.Context, params ResolveQueueUrlParams) (QueueUrlResolverResult, error)
}

type ResolveQueueUrlParams struct {
// Topic passed to Publisher.Publish, Subscriber.Subscribe, etc.
// It may be mapped to a different name by QueueUrlResolver.
Topic string
SqsClient *sqs.Client
Logger watermill.LoggerAdapter
}

type QueueUrlResolverResult struct {
QueueName QueueName

// QueueURL is not present if queue doesn't exist.
QueueURL *QueueURL

// Exists says if queue exists.
// May be nil, if resolver doesn't have information about queue existence.
Exists *bool
}

// GenerateQueueUrlResolver is a resolver that generates queue URL based on AWS region and account ID.
type GenerateQueueUrlResolver struct {
AwsRegion string
AwsAccountID string
}

func (p GenerateQueueUrlResolver) ResolveQueueUrl(ctx context.Context, params ResolveQueueUrlParams) (QueueUrlResolverResult, error) {
queueURL := QueueURL(fmt.Sprintf(
"https://sqs.%s.amazonaws.com/%s/%s",
p.AwsRegion, p.AwsAccountID, params.Topic,
))

return QueueUrlResolverResult{
QueueName: QueueName(params.Topic), // in this case topic maps 1:1 to topic name
QueueURL: &queueURL,
Exists: nil, // we don't know
}, nil
}

type GetQueueUrlByNameUrlResolverConfig struct {
// DoNotCacheQueues disables caching of queue URLs.
DoNotCacheQueues bool
Expand Down Expand Up @@ -179,6 +136,50 @@ func GenerateGetQueueUrlInputDefault(ctx context.Context, topic string) (*sqs.Ge
}, nil
}

// QueueUrlResolver resolves queue URL by topic passed to Publisher.Publish, Subscriber.Subscribe.
type QueueUrlResolver interface {
ResolveQueueUrl(ctx context.Context, params ResolveQueueUrlParams) (QueueUrlResolverResult, error)
}

type ResolveQueueUrlParams struct {
// Topic passed to Publisher.Publish, Subscriber.Subscribe, etc.
// It may be mapped to a different name by QueueUrlResolver.
Topic string
SqsClient *sqs.Client
Logger watermill.LoggerAdapter
}

type QueueUrlResolverResult struct {
QueueName QueueName

// QueueURL is not present if queue doesn't exist.
QueueURL *QueueURL

// Exists says if queue exists.
// May be nil, if resolver doesn't have information about queue existence.
Exists *bool
}

// GenerateQueueUrlResolver is a resolver that generates queue URL based on AWS region and account ID.
// Topic name passed to Publisher.Publish, Subscriber.Subscribe is mapped to queue name.
type GenerateQueueUrlResolver struct {
AwsRegion string
AwsAccountID string
}

func (p GenerateQueueUrlResolver) ResolveQueueUrl(ctx context.Context, params ResolveQueueUrlParams) (QueueUrlResolverResult, error) {
queueURL := QueueURL(fmt.Sprintf(
"https://sqs.%s.amazonaws.com/%s/%s",
p.AwsRegion, p.AwsAccountID, params.Topic,
))

return QueueUrlResolverResult{
QueueName: QueueName(params.Topic), // in this case topic maps 1:1 to topic name
QueueURL: &queueURL,
Exists: nil, // we don't know
}, nil
}

// TransparentUrlResolver is a resolver that uses topic passed to Publisher.Publish, Subscriber.Subscribe as queue URL.
// In this case, you should pass queue URL as topic.
type TransparentUrlResolver struct{}
Expand Down

0 comments on commit 7249cb8

Please sign in to comment.