The go-rscsrv-sqs is the lab259/go-rscsrv service for the Amazon Simple Queue Service (SQS).
It wraps the logic of dealing with credentials and keeping the session.
It depends on the lab259/go-rscsrv (and its dependencies, of course) itself and the aws/aws-sdk-go library.
First, fetch the library to the repository.
go get github.com/lab259/go-rscsrv-sqs
The service is designed to be "extended" and not used directly.
srv.go
package mail
import (
"github.com/lab259/go-rscsrv"
"github.com/lab259/go-rscsrv-sqs"
)
type MessageSQSService struct {
sqssrv.SQSService
}
func (service *MessageSQSService) LoadConfiguration() (interface{}, error) {
var configuration sqssrv.SQSServiceConfiguration
configurationLoader := rscsrv.NewFileConfigurationLoader("/etc/mail")
configurationUnmarshaler := &rscsrv.ConfigurationUnmarshalerYaml{}
config, err := configurationLoader.Load(file)
if err != nil {
return err
}
return configurationUnmarshaler.Unmarshal(config, dst)
if err != nil {
return nil, err
}
return configuration, nil
}
example.go
// ...
var mq rscsrsv.MessageSQSService
func init() {
configuration, err := mq.LoadConfiguration()
if err != nil {
panic(err)
}
err = mq.ApplyConfiguration(configuration)
if err != nil {
panic(err)
}
err = mq.Start()
if err != nil {
panic(err)
}
}
// enqueueMessage enqueues a message
func enqueueMessage(message string) {
output, err := service.SendMessage(&sqs.SendMessageInput{
MessageBody: aws.String("this is the content of the message"),
})
if err != nil {
panic(err)
}
// ... handles the return of the SendMessage
}
// ...
git clone [email protected]:lab259/go-rscsrv-sqs.git # clone the project
cd go-rscsrv-sqs # enter the directory
make dcup # start the ElasticMQ
go mod download # download the dependencies
make test # run the tests