## 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 } ```