pubsub

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NameQueueArn                = "QueueArn"
	NameTopicArn                = "TopicArn"
	QueueAttributeRedrivePolicy = "RedrivePolicy"
)

Variables

View Source
var (
	SubscriptionProtocolSQS   = aws.String("sqs")
	SubscriptionProtocolHTTP  = aws.String("http")
	SubscriptionProtocolHTTPS = aws.String("https")
)

Functions

This section is empty.

Types

type PubsubClient

type PubsubClient struct {
	SQS        *sqs.Client
	SNS        *sns.Client
	Config     sqsConfig
	OpsTimeout time.Duration
}

PubsubClient provides the API clients to make operations call for Amazon Simple Queue Service and Amazon Simple Notification Service

func NewPubsubClient

func NewPubsubClient(sqs *sqs.Client, sns *sns.Client, cfg sqsConfig) (*PubsubClient, error)

NewPubsubClient returns a new client from the provided clients and config.

func (*PubsubClient) CreateQueue

func (c *PubsubClient) CreateQueue(queueName string, opts map[string]*string) (*Queue, error)

CreateQueue calls the CreateQueueContext method.

func (*PubsubClient) CreateQueueContext

func (c *PubsubClient) CreateQueueContext(ctx context.Context, queueName string, opts map[string]*string) (*Queue, error)

CreateQueueContext returns an initialized queue client based on the queue name and options.

func (*PubsubClient) CreateQueueWithDLQ

func (c *PubsubClient) CreateQueueWithDLQ(queueName string, dlq Queue, maxReceive int64, opts map[string]*string) (*Queue, error)

func (*PubsubClient) CreateSubscription

func (c *PubsubClient) CreateSubscription(topic *Topic, queue *Queue, opts map[string]*string) (*Subscription, error)

CreateSubscription calls the CreateSubscriptionContext method.

func (*PubsubClient) CreateSubscriptionContext

func (c *PubsubClient) CreateSubscriptionContext(ctx context.Context, topic *Topic, queue *Queue, opts map[string]*string) (*Subscription, error)

CreateSubscriptionContext returns an initialized subscription client based on the topic, queue and options.

func (*PubsubClient) CreateTopic

func (c *PubsubClient) CreateTopic(topicName string, opts map[string]*string) (*Topic, error)

CreateTopic calls the CreateTopicContext method.

func (*PubsubClient) CreateTopicContext

func (c *PubsubClient) CreateTopicContext(ctx context.Context, topicName string, opts map[string]*string) (*Topic, error)

CreateTopicContext returns an initialized topic client based on the topic name and options.

func (*PubsubClient) NewQueue

func (c *PubsubClient) NewQueue(queueArn string) (*Queue, error)

NewQueue calls the NewQueueContext method.

func (*PubsubClient) NewQueueContext

func (c *PubsubClient) NewQueueContext(ctx context.Context, queueArn string) (*Queue, error)

NewQueueContext returns an initialized queue client based on the queue arn.

func (*PubsubClient) NewSubscription

func (c *PubsubClient) NewSubscription(subscriptionArn string) (*Subscription, error)

NewSubscription calls the NewSubscriptionContext method.

func (*PubsubClient) NewSubscriptionContext

func (c *PubsubClient) NewSubscriptionContext(ctx context.Context, subscriptionArn string) (*Subscription, error)

NewSubscriptionContext returns an initialized subscription client based on the subscription arn.

func (*PubsubClient) NewTopic

func (c *PubsubClient) NewTopic(topicArn string) (*Topic, error)

NewQueue calls the NewTopicContext method.

func (*PubsubClient) NewTopicContext

func (c *PubsubClient) NewTopicContext(ctx context.Context, topicArn string) (*Topic, error)

NewTopicContext returns an initialized topic client based on the topic arn.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue provides a PubsubClient for a specific queue.

func (*Queue) Consume

func (q *Queue) Consume(ctx context.Context, handler func(c context.Context, message string) (bool, error)) error

Consume calls the consume method.

func (*Queue) ConsumeViaS3

func (q *Queue) ConsumeViaS3(ctx context.Context, handler func(c context.Context, event S3Event) (retryable bool, err error)) error

ConsumeViaS3 maps the message to an S3Event struct and calls the consume method.

func (*Queue) ConsumeViaSNS

func (q *Queue) ConsumeViaSNS(ctx context.Context, handler func(c context.Context, event SNSEvent) (retryable bool, err error)) error

ConsumeViaSNS maps the message to an SNSEvent struct and calls the consume method.

func (*Queue) Exist

func (q *Queue) Exist(ctx context.Context) (bool, error)

Exist returns whether the topic exists or not.

func (*Queue) Send

func (q *Queue) Send(ctx context.Context, message string, attributes map[string]types.MessageAttributeValue) error

Send delivers a message to the specified queue.

type S3Event

type S3Event struct {
	Records []struct {
		AwsRegion         string                 `json:"awsRegion"`
		EventName         string                 `json:"eventName"`
		EventTime         string                 `json:"eventTime"`
		EventSource       string                 `json:"eventSource"`
		EventVersion      string                 `json:"eventVersion"`
		UserIdentity      map[string]string      `json:"userIdentity"`
		RequestParameters map[string]interface{} `json:"requestParameters"`
		ResponseElements  map[string]interface{} `json:"responseElements"`
		S3                struct {
			S3SchemaVersion string `json:"s3SchemaVersion"`
			ConfigurationId string `json:"configurationId"`
			Bucket          struct {
				Name          string                 `json:"name"`
				OwnerIdentity map[string]interface{} `json:"ownerIdentity"`
				ARN           string                 `json:"arn"`
			} `json:"bucket"`
			Object struct {
				Key       string `json:"key"`
				Size      int64  `json:"size"`
				ETag      string `json:"etag"`
				Sequencer string `json:"sequencer"`
			} `json:"object"`
		} `json:"s3"`
	}
}

S3Event is the struct to map when sending messages to the queue via s3.

type SNSEvent

type SNSEvent struct {
	Type              string
	MessageId         string
	Message           string
	Token             string
	TopicArn          string
	SubscribeURL      *string
	Timestamp         string
	Signature         string
	SignatureVersion  string
	SigningCertURL    string
	MessageAttributes map[string]map[string]string
}

SNSEvent is the struct to map when sending messages to the queue via topic.

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

Subscription provides a PubsubClient for a specific subscription.

type Topic

type Topic struct {
	// contains filtered or unexported fields
}

Topic provides a PubsubClient for a specific topic.

func (*Topic) Exist

func (t *Topic) Exist(ctx context.Context) (bool, error)

Exist returns whether the topic exists or not.

func (*Topic) Publish

func (t *Topic) Publish(ctx context.Context, message string, attributes map[string]types.MessageAttributeValue) error

Publish sends a message to an Amazon SNS topic, a text message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL