Go - NewQueue()

Creates a new Queue to send and receive asynchronous tasks.

import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  queue, err := nitric.NewQueue("queue-name").With(nitric.QueueSending, nitric.QueueReceiving)
  if err != nil {
    fmt.Prinln(err)
    return
  }

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}

Parameters

  • Name
    name
    Required
    Required
    Type
    string
    Description

    The unique name of this Queue within the app. Subsequent calls to NewQueue with the same name will return the same object.

Access

All Nitric resources provide access permissions you can use to specify the level of access your code needs to the resource. See here for details Access Control documentation.

Available permissions:


QueueSending

This permission allows your code to send new tasks to the queue.


QueueReceiving

This permission allows your code to receive tasks from the queue.


Notes

In most instances, code should either send to or receive from a queue, usually not both.

Examples

Create a Queue

import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  queue, err := nitric.NewQueue("queue-name").With(nitric.QueueSending, nitric.QueueReceiving)
  if err != nil {
    fmt.Prinln(err)
    return
  }

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}

Receive tasks from a queue

import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  queue, err := nitric.NewQueue("queue-name").With(nitric.QueueReceiving)
  if err != nil {
    fmt.Prinln(err)
    return
  }

  tasks := queue.Receive(context.TODO(), 10)

  if err := nitric.Run(); err != nil {
    fmt.Println(err)
  }
}

See also