tarantool队列尝试索引全局'队列'

时间:2017-09-14 12:12:07

标签: go queue tarantool

  1. 我有错误: que := queue.New(conn, "foobar") :错误评估:1:尝试索引全局'队列'(零值)(0x20)

  2. 配置文件:(如果我删除box.once,那么erros管存在) 如何纠正init用户和管道配置,没有错误'用户已经存在'?

  3. `

    box.cfg {listen=3303}
    local queue = require('queue')
    queue.start()
    queue.create_tube('foobar', 'fifottl', {if_not_exists=true})
    box.once("init", function()
        box.schema.user.grant('guest', 'read,write,execute', 'universe')
    end)
    

    `

    代码: `

    func TestTarantoolQueue(t *testing.T)  {
        //opts := tarantool.Opts{User: "test", Pass: "test"}
        opts := tarantool.Opts{}
        conn, err := tarantool.Connect("127.0.0.1:3303", opts)
        if err != nil {
            t.Log("Error", err)
            t.FailNow()
        }
        cfg := queue.Cfg{
            Temporary: true,
            IfNotExists: true,
            Kind: queue.FIFO_TTL,
            Opts: queue.Opts{
                Ttl: 10 * time.Second,
                Ttr: 5 * time.Second,
                Delay: 3 * time.Second,
                Pri: 1,
            },
        }
        que := queue.New(conn, "foobar")
        err = que.Create(cfg)
        if err != nil {
            t.Log("Error", err)
            t.FailNow()
        }
        task, err := que.Put("test_data")
        if err != nil {
            t.Log("Error", err)
            t.FailNow()
        }
        fmt.Println("Task id is ", task.Id())
        task, err = que.Take() //blocking operation
        if err != nil {
            t.Log("Error", err)
            t.FailNow()
        }
        fmt.Println("Data is ", task.Data())
        task.Ack()
        task, err = que.Put([]int{1, 2, 3})
        if err != nil {
            t.Log("Error", err)
            t.FailNow()
        }
        task.Bury()
        task, err = que.TakeTimeout(2 * time.Second)
        if task == nil {
            fmt.Println("Task is nil")
        }
        que.Drop()
    }
    

    `

1 个答案:

答案 0 :(得分:0)

local删除local queue = require('queue')可以解决问题。