コード例 #1
0
ファイル: create_queue.go プロジェクト: vburenin/firempq
func CreateQueue(svcMgr *qmgr.ServiceManager, sqsQuery *urlutils.SQSQuery) sqs_response.SQSResponse {
	queueAttributes, parseErr := ParseCreateQueueAttributes(sqsQuery)
	if parseErr != nil {
		return parseErr
	}

	if errResp := CheckAvailableQueues(svcMgr, queueAttributes, sqsQuery); errResp != nil {
		return errResp
	}

	resp := svcMgr.CreatePQueue(sqsQuery.QueueName, queueAttributes.MakePQConfig())
	if resp.IsError() {
		e, _ := resp.(error)
		return sqserr.ServerSideError(e.Error())
	}

	return &CreateQueueResponse{
		QueueUrl:  sqsQuery.Host + "/queue/" + sqsQuery.QueueName,
		RequestId: "1111-2222-3333",
	}
}
コード例 #2
0
ファイル: create_queue.go プロジェクト: vburenin/firempq
func CheckAvailableQueues(
	svcMgr *qmgr.ServiceManager,
	attr *QueueAttributes,
	sqsQuery *urlutils.SQSQuery) sqs_response.SQSResponse {

	svc, ok := svcMgr.GetService(sqsQuery.QueueName)
	if ok {
		if svc.Info().Type != apis.ServiceTypePriorityQueue {
			return sqserr.QueueAlreadyExistsError("Queue already exists for a different type of service")
		}
		pq, _ := svc.(*pqueue.PQueue)
		pqConfig := pq.Config()
		if !ok {
			log.Error("Unexpected config type from the found service!")
			return sqserr.ServerSideError("Queue config data error")
		}
		if attr.VisibilityTimeout >= 0 && attr.VisibilityTimeout != pqConfig.PopLockTimeout {
			return sqserr.QueueAlreadyExistsError(errQueueExists + AttrVisibilityTimeout)
		}
		if attr.DelaySeconds >= 0 && attr.DelaySeconds != pqConfig.DeliveryDelay {
			return sqserr.QueueAlreadyExistsError(errQueueExists + AttrDelaySeconds)
		}
		if attr.MaximumMessageSize >= 0 && attr.MaximumMessageSize != pqConfig.MaxMsgSize {
			return sqserr.QueueAlreadyExistsError(errQueueExists + AttrMaximumMessageSize)
		}
		if attr.MessageRetentionPeriod >= 0 && attr.MessageRetentionPeriod != pqConfig.MsgTtl {
			return sqserr.QueueAlreadyExistsError(errQueueExists + AttrMessageRetentionPeriod)
		}
		if attr.ReceiveMessageWaitTimeSeconds >= 0 && attr.ReceiveMessageWaitTimeSeconds != pqConfig.PopWaitTimeout {
			return sqserr.QueueAlreadyExistsError(errQueueExists + AttrReceiveMessageWaitTimeSeconds)
		}
		return &CreateQueueResponse{
			QueueUrl:  sqsQuery.Host + "/queue/" + sqsQuery.QueueName,
			RequestId: "1111-2222-3333",
		}
	}
	return nil
}