type Server struct {
pipeline.Env
session *session.Session
sqsClient *sqs.SQS
snsClient *sns.SNS
s3Client *s3.S3
b string
ch string
}
func (s *Server) Message() error {
// URL to our queue
qURL := fmt.Sprintf("https://sqs.xx.com/xx311/xx_%s_queue_%s", s.b, s.u)
resultSQS, err := s.sqsClient.ReceiveMessage(&sqs.ReceiveMessageInput{
AttributeNames: []*string{
aws.String(sqs.MessageSystemAttributeNameSentTimestamp),
},
MessageAttributeNames: []*string{
aws.String(sqs.QueueAttributeNameAll),
},
QueueUrl: &qURL,
MaxNumberOfMessages: aws.Int64(10),
VisibilityTimeout: aws.Int64(60), // seconds
WaitTimeSeconds: aws.Int64(1),
})
if err != nil {
s.Errorf("Error: %+v\n", err)
return err
}
if len(resultSQS.Messages) > 0 {
for _, msg := range resultSQS.Messages {
var receivedMessage model.xxMessage
var pEvent model.PPayload
delete_params := &sqs.DeleteMessageInput{
QueueUrl: &qURL,
ReceiptHandle: msg.ReceiptHandle,
}
_, err := s.sqsClient.DeleteMessage(delete_params)
if err != nil {
s.Errorf("delete message failed: %v", err)
continue
}
// s.Printf("pipeline state: %v\n", *msg.Body)
if err := json.Unmarshal([]byte(*msg.Body), &receivedMessage); err != nil {
s.Errorf("malformat SQS Message %v", err)
continue
}
s.Printf("TEST %s\n", receivedMessage.Message)
if err := json.Unmarshal([]byte(receivedMessage.Message), &pipelineEvent); err != nil {
s.Errorf("malformat P Message %v", err)
}
}
}
return nil
}