|
| 1 | +package queues |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/gophercloud/gophercloud" |
| 5 | +) |
| 6 | + |
| 7 | +// CreateOptsBuilder allows extensions to add additional parameters to the |
| 8 | +// Create request. |
| 9 | +type CreateOptsBuilder interface { |
| 10 | + ToQueueCreateMap() (map[string]interface{}, error) |
| 11 | +} |
| 12 | + |
| 13 | +// CreateOpts specifies the queue creation parameters. |
| 14 | +type CreateOpts struct { |
| 15 | + // The name of the queue to create. |
| 16 | + QueueName string `json:"queue_name" required:"true"` |
| 17 | + |
| 18 | + // The target incoming messages will be moved to when a message can’t |
| 19 | + // processed successfully after meet the max claim count is met. |
| 20 | + DeadLetterQueue string `json:"_dead_letter_queue,omitempty"` |
| 21 | + |
| 22 | + // The new TTL setting for messages when moved to dead letter queue. |
| 23 | + DeadLetterQueueMessagesTTL int `json:"_dead_letter_queue_messages_ttl,omitempty"` |
| 24 | + |
| 25 | + // The delay of messages defined for a queue. When the messages send to |
| 26 | + // the queue, it will be delayed for some times and means it can not be |
| 27 | + // claimed until the delay expired. |
| 28 | + DefaultMessageDelay int `json:"_default_message_delay,omitempty"` |
| 29 | + |
| 30 | + // The default TTL of messages defined for a queue, which will effect for |
| 31 | + // any messages posted to the queue. |
| 32 | + DefaultMessageTTL int `json:"_default_message_ttl" required:"true"` |
| 33 | + |
| 34 | + // The flavor name which can tell Zaqar which storage pool will be used |
| 35 | + // to create the queue. |
| 36 | + Flavor string `json:"_flavor,omitempty"` |
| 37 | + |
| 38 | + // The max number the message can be claimed. |
| 39 | + MaxClaimCount int `json:"_max_claim_count,omitempty"` |
| 40 | + |
| 41 | + // The max post size of messages defined for a queue, which will effect |
| 42 | + // for any messages posted to the queue. |
| 43 | + MaxMessagesPostSize int `json:"_max_messages_post_size,omitempty"` |
| 44 | + |
| 45 | + // Extra is free-form extra key/value pairs to describe the queue. |
| 46 | + Extra map[string]interface{} `json:"-"` |
| 47 | +} |
| 48 | + |
| 49 | +// ToQueueCreateMap constructs a request body from CreateOpts. |
| 50 | +func (opts CreateOpts) ToQueueCreateMap() (map[string]interface{}, error) { |
| 51 | + b, err := gophercloud.BuildRequestBody(opts, "") |
| 52 | + if err != nil { |
| 53 | + return nil, err |
| 54 | + } |
| 55 | + |
| 56 | + if opts.Extra != nil { |
| 57 | + for key, value := range opts.Extra { |
| 58 | + b[key] = value |
| 59 | + } |
| 60 | + |
| 61 | + } |
| 62 | + return b, nil |
| 63 | +} |
| 64 | + |
| 65 | +// Create requests the creation of a new queue. |
| 66 | +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { |
| 67 | + b, err := opts.ToQueueCreateMap() |
| 68 | + if err != nil { |
| 69 | + r.Err = err |
| 70 | + return |
| 71 | + } |
| 72 | + |
| 73 | + queueName := b["queue_name"].(string) |
| 74 | + delete(b, "queue_name") |
| 75 | + |
| 76 | + _, r.Err = client.Put(createURL(client, queueName), b, r.Body, &gophercloud.RequestOpts{ |
| 77 | + OkCodes: []int{201, 204}, |
| 78 | + }) |
| 79 | + return |
| 80 | +} |
0 commit comments