github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dms/v1/queues/requests.go (about)

     1  package queues
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // CreateOpsBuilder is used for creating queue parameters.
     9  // any struct providing the parameters should implement this interface
    10  type CreateOpsBuilder interface {
    11  	ToQueueCreateMap() (map[string]interface{}, error)
    12  }
    13  
    14  // CreateOps is a struct that contains all the parameters.
    15  type CreateOps struct {
    16  	// Indicates the unique name of a queue.
    17  	// A string of 1 to 64 characters that contain
    18  	// a-z, A-Z, 0-9, hyphens (-), and underscores (_).
    19  	// The name cannot be modified once specified.
    20  	Name string `json:"name" required:"true"`
    21  
    22  	// Indicates the queue type. Default value: NORMAL. Options:
    23  	// NORMAL: Standard queue. Best-effort ordering.
    24  	// FIFO: First-ln-First-out (FIFO) queue. FIFO delivery.
    25  	// KAFKA_HA: High-availability Kafka queue.
    26  	// KAFKA_HT: High-throughput Kafka queue.
    27  	// AMQP: Advanced Message Queuing Protocol (AMQP) queue.
    28  	QueueMode string `json:"queue_mode,omitempty"`
    29  
    30  	// Indicates the basic information about a queue.
    31  	// The queue description must be 0 to 160 characters in length,
    32  	// and does not contain angle brackets (<) and (>).
    33  	Description string `json:"description,omitempty"`
    34  
    35  	// This parameter is mandatory only when queue_mode is NORMAL or FIFO.
    36  	// Indicates whether to enable dead letter messages.
    37  	// Default value: disable. Options: enable, disable.
    38  	RedrivePolicy string `json:"redrive_policy,omitempty"`
    39  
    40  	// This parameter is mandatory only when
    41  	// redrive_policy is set to enable.
    42  	// This parameter indicates the maximum number
    43  	// of allowed message consumption failures.
    44  	// Value range: 1-100.
    45  	MaxConsumeCount int `json:"max_consume_count,omitempty"`
    46  
    47  	// This parameter is mandatory only when
    48  	// queue_mode is set to KAFKA_HA or KAFKA_HT.
    49  	// This parameter indicates the retention time
    50  	// of messages in Kafka queues.
    51  	// Value range: 1 to 72 hours.
    52  	RetentionHours int `json:"retention_hours,omitempty"`
    53  }
    54  
    55  // ToQueueCreateMap is used for type convert
    56  func (ops CreateOps) ToQueueCreateMap() (map[string]interface{}, error) {
    57  	return golangsdk.BuildRequestBody(ops, "")
    58  }
    59  
    60  // Create a queue with given parameters.
    61  func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) {
    62  	b, err := ops.ToQueueCreateMap()
    63  	if err != nil {
    64  		r.Err = err
    65  		return
    66  	}
    67  
    68  	_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
    69  		OkCodes: []int{201},
    70  	})
    71  
    72  	return
    73  }
    74  
    75  // Delete a queue by id
    76  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
    77  	_, r.Err = client.Delete(deleteURL(client, id), nil)
    78  	return
    79  }
    80  
    81  // Get a queue with detailed information by id
    82  func Get(client *golangsdk.ServiceClient, id string, includeDeadLetter bool) (r GetResult) {
    83  	_, r.Err = client.Get(getURL(client, id, includeDeadLetter), &r.Body, nil)
    84  	return
    85  }
    86  
    87  // List all the queues
    88  func List(client *golangsdk.ServiceClient, includeDeadLetter bool) pagination.Pager {
    89  	url := listURL(client, includeDeadLetter)
    90  
    91  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    92  		return QueuePage{pagination.SinglePageBase(r)}
    93  	})
    94  }