Ejemplo n.º 1
0
// Connect connects to SQS discovering SQS URL for a given queue name.
func Connect(session *session.Session, queueName string) (SQSInterface, error) {
	s := sqs.New(session)

	gq := &sqs.GetQueueUrlInput{
		QueueName: &queueName,
	}
	resp, err := s.GetQueueUrl(gq)

	if err != nil {
		return nil, err
	}
	psqs := &NiceSQS{
		Sqs:      s,
		queueUrl: resp.QueueUrl,
		sema:     nsync.NewSemaphore(DefaultParallelRequestsLimit),
	}
	return psqs, nil
}
Ejemplo n.º 2
0
// CreateQueue creates a queue with the specific name and user defined options.
func CreateQueue(session *session.Session, queueName string, opts *SQSOptions) (SQSInterface, error) {
	s := sqs.New(session)
	cqi := &sqs.CreateQueueInput{
		QueueName: &queueName,
	}
	if opts != nil {
		cqi.Attributes = opts.toOptionsMap()
	}

	resp, err := s.CreateQueue(cqi)
	if err != nil {
		return nil, err
	}

	return &NiceSQS{
		Sqs:      s,
		queueUrl: resp.QueueUrl,
		sema:     nsync.NewSemaphore(DefaultParallelRequestsLimit),
	}, nil
}
Ejemplo n.º 3
0
// SetParallelLimit sets a goroutine limit that can be used to
// do concurrent SQS requests.
// If you change a limit, make sure there are no other goroutines
// running, otherwise it will cause panic.
func (this *NiceSQS) SetParallelLimit(limit int) *NiceSQS {
	this.sema = nsync.NewSemaphore(limit)
	return this
}