func BuildSQSListener(addr *SQSAddr, handler SQSHandler, pollInterval time.Duration) *SQSListener { return &SQSListener{ SQSClient: sqs.New(addr.Auth, addr.Region), PollInterval: pollInterval, Queue: addr, Handler: handler, closeRequested: make(chan bool), closed: make(chan bool), } }
func BuildSQSClient(auth aws.Auth, region aws.Region) *SQSClient { m := make(MessageCreator) m.RegisterMessageType("error", func(args ...interface{}) (string, error) { return fmt.Sprintf("%v", args...), nil }) return &SQSClient{ Signer: &m, SQS: sqs.New(auth, region), } }
func main() { defaultExpiration = 10000 usr, err := user.Current() homeDir := "." if err != nil { log.Println("Error gettingcurrent user ", err) } else { homeDir = usr.HomeDir log.Println(" User ", usr, " Home Dir := ", homeDir) } authCreds, err = aws.CredentialFileAuth(homeDir+"/.aws/credentials", "default", defaultExpiration) awsRegion = aws.Regions[defaultAwsRegionName] if err != nil { log.Println(" Error getting Authentication Creds : ", err) } sqsService = sqs.New(authCreds, awsRegion) sqsQueue, err = sqsService.GetQueue(sqsQueueName) if err != nil { log.Println("Error getting SQS Queue (", sqsQueueName, ") : ", err) } log.Println("Sending Message...") messageBody := "Hello World!" sendResponse, err := sqsQueue.SendMessage(messageBody) if err != nil { log.Fatal("Message Sending Error : ", err) } else { log.Println("Message Send Response = ", sendResponse) } log.Println("Receiving Message...") receiveResponse, err := sqsQueue.ReceiveMessage(1) if err != nil { log.Println("Error receiving next message : ", err) return } log.Println(" Receive Response : ", receiveResponse) if len(receiveResponse.Messages) > 0 { for _, msg := range receiveResponse.Messages { msgAttrbs := msg.MessageAttribute log.Println(" Message := ", msg, " Attributes = ", msgAttrbs) } } else { log.Println("No Messages found in the Queue") } log.Println("Deleting the received Message after processing !") if len(receiveResponse.Messages) > 0 { for _, msg := range receiveResponse.Messages { deleteResponse, err := sqsQueue.DeleteMessage(&msg) log.Println(" Delete Response := ", deleteResponse, " Error = ", err) } } }
func main() { sleepTime := time.Millisecond * 5000 // 5 seconds receiveMessageNum := 10 fmt.Println("===========================================") fmt.Println(fmt.Sprintf(" Use CPU(s) num : %d", runtime.NumCPU())) fmt.Println(fmt.Sprintf(" Receive message num : %d", receiveMessageNum)) fmt.Println(fmt.Sprintf(" Sleep time : 5 second(s)")) fmt.Println("===========================================") runtime.GOMAXPROCS(runtime.NumCPU()) auth := aws.Auth{AccessKey: amazonAccessKey, SecretKey: amazonSecretKey} mySqs := sqs.New(auth, aws.EUWest) queue := &sqs.Queue{mySqs, amazonQueueName} client := twilio.NewClient(twilioSid, twilioAt) worker_sms.Start(queue, worker_sms.HandlerFunc(Print), sleepTime, receiveMessageNum, client, twilioSender) }
func (locator Locator) LookupQueue() (*sqs.Queue, error) { // login to sqs, reading our credentials from the environment auth, err := aws.EnvAuth() if err != nil { return nil, err } // connect to our sqs q region, found := aws.Regions[locator.RegionName] if !found { return nil, errors.New(fmt.Sprintf("no such region, '%s'", locator.RegionName)) } log.Printf("looking up sqs queue by name, '%s'\n", locator.QueueName) sqsService := sqs.New(auth, region) q, err := sqsService.GetQueue(locator.QueueName) if err != nil { return nil, err } log.Printf("%s: ok\n", locator.QueueName) return q, nil }
func (s *S) SetUpSuite(c *gocheck.C) { s.HTTPSuite.SetUpSuite(c) auth := aws.Auth{AccessKey: "abc", SecretKey: "123"} s.sqs = sqs.New(auth, aws.Region{SQSEndpoint: testServer.URL}) }
func makeSQSConnection(a *SQSAddr) *sqs.SQS { return sqs.New(a.Auth, a.Region) }