# Consumers ## List Queue Consumers `client.Queues.Consumers.List(ctx, queueID, query) (*SinglePage[Consumer], error)` **get** `/accounts/{account_id}/queues/{queue_id}/consumers` Returns the consumers for a Queue ### Parameters - `queueID string` A Resource identifier. - `query ConsumerListParams` - `AccountID param.Field[string]` A Resource identifier. ### Returns - `type Consumer interface{…}` Response body representing a consumer - `type ConsumerMqWorkerConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `ScriptName string` Name of a Worker - `Settings ConsumerMqWorkerConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxConcurrency float64` Maximum number of concurrent consumers that may consume from this Queue. Set to `null` to automatically opt in to the platform's maximum (recommended). - `MaxRetries float64` The maximum number of retries - `MaxWaitTimeMs float64` The number of milliseconds to wait for a batch to fill up before attempting to deliver it - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `Type ConsumerMqWorkerConsumerResponseType` - `const ConsumerMqWorkerConsumerResponseTypeWorker ConsumerMqWorkerConsumerResponseType = "worker"` - `type ConsumerMqHTTPConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `Settings ConsumerMqHTTPConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxRetries float64` The maximum number of retries - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `VisibilityTimeoutMs float64` The number of milliseconds that a message is exclusively leased. After the timeout, the message becomes available for another attempt. - `Type ConsumerMqHTTPConsumerResponseType` - `const ConsumerMqHTTPConsumerResponseTypeHTTPPull ConsumerMqHTTPConsumerResponseType = "http_pull"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/queues" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.Queues.Consumers.List( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", queues.ConsumerListParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 7003, "message": "No route for the URI", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ "string" ], "result": [ { "consumer_id": "023e105f4ecef8ad9ca31a8372d0c353", "created_on": "2019-12-27T18:11:19.117Z", "dead_letter_queue": "dead_letter_queue", "queue_name": "example-queue", "script_name": "my-consumer-worker", "settings": { "batch_size": 50, "max_concurrency": 10, "max_retries": 3, "max_wait_time_ms": 5000, "retry_delay": 10 }, "type": "worker" } ], "success": true } ``` ## Get Queue Consumer `client.Queues.Consumers.Get(ctx, queueID, consumerID, query) (*Consumer, error)` **get** `/accounts/{account_id}/queues/{queue_id}/consumers/{consumer_id}` Fetches the consumer for a queue by consumer id ### Parameters - `queueID string` A Resource identifier. - `consumerID string` A Resource identifier. - `query ConsumerGetParams` - `AccountID param.Field[string]` A Resource identifier. ### Returns - `type Consumer interface{…}` Response body representing a consumer - `type ConsumerMqWorkerConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `ScriptName string` Name of a Worker - `Settings ConsumerMqWorkerConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxConcurrency float64` Maximum number of concurrent consumers that may consume from this Queue. Set to `null` to automatically opt in to the platform's maximum (recommended). - `MaxRetries float64` The maximum number of retries - `MaxWaitTimeMs float64` The number of milliseconds to wait for a batch to fill up before attempting to deliver it - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `Type ConsumerMqWorkerConsumerResponseType` - `const ConsumerMqWorkerConsumerResponseTypeWorker ConsumerMqWorkerConsumerResponseType = "worker"` - `type ConsumerMqHTTPConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `Settings ConsumerMqHTTPConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxRetries float64` The maximum number of retries - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `VisibilityTimeoutMs float64` The number of milliseconds that a message is exclusively leased. After the timeout, the message becomes available for another attempt. - `Type ConsumerMqHTTPConsumerResponseType` - `const ConsumerMqHTTPConsumerResponseTypeHTTPPull ConsumerMqHTTPConsumerResponseType = "http_pull"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/queues" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) consumer, err := client.Queues.Consumers.Get( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", "023e105f4ecef8ad9ca31a8372d0c353", queues.ConsumerGetParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", consumer) } ``` #### Response ```json { "errors": [ { "code": 7003, "message": "No route for the URI", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ "string" ], "result": { "consumer_id": "023e105f4ecef8ad9ca31a8372d0c353", "created_on": "2019-12-27T18:11:19.117Z", "dead_letter_queue": "dead_letter_queue", "queue_name": "example-queue", "script_name": "my-consumer-worker", "settings": { "batch_size": 50, "max_concurrency": 10, "max_retries": 3, "max_wait_time_ms": 5000, "retry_delay": 10 }, "type": "worker" }, "success": true } ``` ## Create a Queue Consumer `client.Queues.Consumers.New(ctx, queueID, params) (*Consumer, error)` **post** `/accounts/{account_id}/queues/{queue_id}/consumers` Creates a new consumer for a Queue ### Parameters - `queueID string` A Resource identifier. - `params ConsumerNewParams` - `AccountID param.Field[string]` Path param: A Resource identifier. - `ScriptName param.Field[string]` Body param: Name of a Worker - `Type param.Field[ConsumerNewParamsMqWorkerConsumerRequestType]` Body param - `const ConsumerNewParamsMqWorkerConsumerRequestTypeWorker ConsumerNewParamsMqWorkerConsumerRequestType = "worker"` - `DeadLetterQueue param.Field[string]` Body param - `Settings param.Field[ConsumerNewParamsMqWorkerConsumerRequestSettings]` Body param - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxConcurrency float64` Maximum number of concurrent consumers that may consume from this Queue. Set to `null` to automatically opt in to the platform's maximum (recommended). - `MaxRetries float64` The maximum number of retries - `MaxWaitTimeMs float64` The number of milliseconds to wait for a batch to fill up before attempting to deliver it - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. ### Returns - `type Consumer interface{…}` Response body representing a consumer - `type ConsumerMqWorkerConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `ScriptName string` Name of a Worker - `Settings ConsumerMqWorkerConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxConcurrency float64` Maximum number of concurrent consumers that may consume from this Queue. Set to `null` to automatically opt in to the platform's maximum (recommended). - `MaxRetries float64` The maximum number of retries - `MaxWaitTimeMs float64` The number of milliseconds to wait for a batch to fill up before attempting to deliver it - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `Type ConsumerMqWorkerConsumerResponseType` - `const ConsumerMqWorkerConsumerResponseTypeWorker ConsumerMqWorkerConsumerResponseType = "worker"` - `type ConsumerMqHTTPConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `Settings ConsumerMqHTTPConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxRetries float64` The maximum number of retries - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `VisibilityTimeoutMs float64` The number of milliseconds that a message is exclusively leased. After the timeout, the message becomes available for another attempt. - `Type ConsumerMqHTTPConsumerResponseType` - `const ConsumerMqHTTPConsumerResponseTypeHTTPPull ConsumerMqHTTPConsumerResponseType = "http_pull"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/queues" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) consumer, err := client.Queues.Consumers.New( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", queues.ConsumerNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Body: queues.ConsumerNewParamsBodyMqWorkerConsumerRequest{ ScriptName: cloudflare.F("my-consumer-worker"), Type: cloudflare.F(queues.ConsumerNewParamsBodyMqWorkerConsumerRequestTypeWorker), }, }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", consumer) } ``` #### Response ```json { "errors": [ { "code": 7003, "message": "No route for the URI", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ "string" ], "result": { "consumer_id": "023e105f4ecef8ad9ca31a8372d0c353", "created_on": "2019-12-27T18:11:19.117Z", "dead_letter_queue": "dead_letter_queue", "queue_name": "example-queue", "script_name": "my-consumer-worker", "settings": { "batch_size": 50, "max_concurrency": 10, "max_retries": 3, "max_wait_time_ms": 5000, "retry_delay": 10 }, "type": "worker" }, "success": true } ``` ## Update Queue Consumer `client.Queues.Consumers.Update(ctx, queueID, consumerID, params) (*Consumer, error)` **put** `/accounts/{account_id}/queues/{queue_id}/consumers/{consumer_id}` Updates the consumer for a queue, or creates one if it does not exist. ### Parameters - `queueID string` A Resource identifier. - `consumerID string` A Resource identifier. - `params ConsumerUpdateParams` - `AccountID param.Field[string]` Path param: A Resource identifier. - `ScriptName param.Field[string]` Body param: Name of a Worker - `Type param.Field[ConsumerUpdateParamsMqWorkerConsumerRequestType]` Body param - `const ConsumerUpdateParamsMqWorkerConsumerRequestTypeWorker ConsumerUpdateParamsMqWorkerConsumerRequestType = "worker"` - `DeadLetterQueue param.Field[string]` Body param - `Settings param.Field[ConsumerUpdateParamsMqWorkerConsumerRequestSettings]` Body param - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxConcurrency float64` Maximum number of concurrent consumers that may consume from this Queue. Set to `null` to automatically opt in to the platform's maximum (recommended). - `MaxRetries float64` The maximum number of retries - `MaxWaitTimeMs float64` The number of milliseconds to wait for a batch to fill up before attempting to deliver it - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. ### Returns - `type Consumer interface{…}` Response body representing a consumer - `type ConsumerMqWorkerConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `ScriptName string` Name of a Worker - `Settings ConsumerMqWorkerConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxConcurrency float64` Maximum number of concurrent consumers that may consume from this Queue. Set to `null` to automatically opt in to the platform's maximum (recommended). - `MaxRetries float64` The maximum number of retries - `MaxWaitTimeMs float64` The number of milliseconds to wait for a batch to fill up before attempting to deliver it - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `Type ConsumerMqWorkerConsumerResponseType` - `const ConsumerMqWorkerConsumerResponseTypeWorker ConsumerMqWorkerConsumerResponseType = "worker"` - `type ConsumerMqHTTPConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `Settings ConsumerMqHTTPConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxRetries float64` The maximum number of retries - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `VisibilityTimeoutMs float64` The number of milliseconds that a message is exclusively leased. After the timeout, the message becomes available for another attempt. - `Type ConsumerMqHTTPConsumerResponseType` - `const ConsumerMqHTTPConsumerResponseTypeHTTPPull ConsumerMqHTTPConsumerResponseType = "http_pull"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/queues" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) consumer, err := client.Queues.Consumers.Update( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", "023e105f4ecef8ad9ca31a8372d0c353", queues.ConsumerUpdateParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Body: queues.ConsumerUpdateParamsBodyMqWorkerConsumerRequest{ ScriptName: cloudflare.F("my-consumer-worker"), Type: cloudflare.F(queues.ConsumerUpdateParamsBodyMqWorkerConsumerRequestTypeWorker), }, }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", consumer) } ``` #### Response ```json { "errors": [ { "code": 7003, "message": "No route for the URI", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ "string" ], "result": { "consumer_id": "023e105f4ecef8ad9ca31a8372d0c353", "created_on": "2019-12-27T18:11:19.117Z", "dead_letter_queue": "dead_letter_queue", "queue_name": "example-queue", "script_name": "my-consumer-worker", "settings": { "batch_size": 50, "max_concurrency": 10, "max_retries": 3, "max_wait_time_ms": 5000, "retry_delay": 10 }, "type": "worker" }, "success": true } ``` ## Delete Queue Consumer `client.Queues.Consumers.Delete(ctx, queueID, consumerID, body) (*ConsumerDeleteResponse, error)` **delete** `/accounts/{account_id}/queues/{queue_id}/consumers/{consumer_id}` Deletes the consumer for a queue. ### Parameters - `queueID string` A Resource identifier. - `consumerID string` A Resource identifier. - `body ConsumerDeleteParams` - `AccountID param.Field[string]` A Resource identifier. ### Returns - `type ConsumerDeleteResponse struct{…}` - `Errors []ResponseInfo` - `Code int64` - `Message string` - `DocumentationURL string` - `Source ResponseInfoSource` - `Pointer string` - `Messages []string` - `Success ConsumerDeleteResponseSuccess` Indicates if the API call was successful or not. - `const ConsumerDeleteResponseSuccessTrue ConsumerDeleteResponseSuccess = true` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/queues" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) consumer, err := client.Queues.Consumers.Delete( context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353", "023e105f4ecef8ad9ca31a8372d0c353", queues.ConsumerDeleteParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", consumer.Errors) } ``` #### Response ```json { "errors": [ { "code": 7003, "message": "No route for the URI", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ "string" ], "success": true } ``` ## Domain Types ### Consumer - `type Consumer interface{…}` Response body representing a consumer - `type ConsumerMqWorkerConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `ScriptName string` Name of a Worker - `Settings ConsumerMqWorkerConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxConcurrency float64` Maximum number of concurrent consumers that may consume from this Queue. Set to `null` to automatically opt in to the platform's maximum (recommended). - `MaxRetries float64` The maximum number of retries - `MaxWaitTimeMs float64` The number of milliseconds to wait for a batch to fill up before attempting to deliver it - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `Type ConsumerMqWorkerConsumerResponseType` - `const ConsumerMqWorkerConsumerResponseTypeWorker ConsumerMqWorkerConsumerResponseType = "worker"` - `type ConsumerMqHTTPConsumerResponse struct{…}` - `ConsumerID string` A Resource identifier. - `CreatedOn Time` - `DeadLetterQueue string` Name of the dead letter queue, or empty string if not configured - `QueueName string` - `Settings ConsumerMqHTTPConsumerResponseSettings` - `BatchSize float64` The maximum number of messages to include in a batch. - `MaxRetries float64` The maximum number of retries - `RetryDelay float64` The number of seconds to delay before making the message available for another attempt. - `VisibilityTimeoutMs float64` The number of milliseconds that a message is exclusively leased. After the timeout, the message becomes available for another attempt. - `Type ConsumerMqHTTPConsumerResponseType` - `const ConsumerMqHTTPConsumerResponseTypeHTTPPull ConsumerMqHTTPConsumerResponseType = "http_pull"`