ReceiveMessageWithContext sends the first message for the requested queue, if any, then removes it from the queue.
(ctx aws.Context, input *sqs.ReceiveMessageInput, options ...request.Option)
| 484 | // ReceiveMessageWithContext sends the first message for the requested queue, if |
| 485 | // any, then removes it from the queue. |
| 486 | func (c *mockSQSClient) ReceiveMessageWithContext(ctx aws.Context, input *sqs.ReceiveMessageInput, options ...request.Option) (*sqs.ReceiveMessageOutput, error) { |
| 487 | c.mu.Lock() |
| 488 | defer c.mu.Unlock() |
| 489 | |
| 490 | time.Sleep(50 * time.Millisecond) |
| 491 | |
| 492 | u, err := url.Parse(*input.QueueUrl) |
| 493 | if err != nil { |
| 494 | return nil, err |
| 495 | } |
| 496 | ucomps := strings.Split(u.Path, "/") |
| 497 | queueName := ucomps[len(ucomps)-1] |
| 498 | msgs, ok := c.queues[queueName] |
| 499 | if !ok { |
| 500 | return nil, fmt.Errorf("queue %v not found", queueName) |
| 501 | } |
| 502 | |
| 503 | out := &sqs.ReceiveMessageOutput{ |
| 504 | Messages: []*sqs.Message{}, |
| 505 | } |
| 506 | |
| 507 | if len(msgs) > 0 { |
| 508 | // Pops the first message out of the queue. |
| 509 | var first sqs.Message |
| 510 | first, msgs = msgs[0], msgs[1:] |
| 511 | out.Messages = append(out.Messages, &first) |
| 512 | c.queues[queueName] = msgs |
| 513 | } |
| 514 | |
| 515 | log.WithFields(log.Fields{"sqs": "ReceiveMessageWithContext", "input": *input, "out": *out}).Debug() |
| 516 | return out, nil |
| 517 | } |
| 518 | |
| 519 | // DeleteMessageWithContext does nothing since messages are removed from the |
| 520 | // queue as soon as they're requested. |