github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dms/v1/queues/requests.go (about)

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