2018-06-17 13:12 浏览 46


I need to publish a task by name (creating a message on a queue with task name passed in headers, passing some args).

I've done this in Celery (Python) like this:

celery_app.send_task("task_name", args=("arg1", "arg2",))

Here's my code in Go to do the same thing:

headers := make(amqp.Table)
headers["argsrepr"] = []string{"arg1", "arg2"}
headers["task"] = "task_name"

body := ""
jsonBody, _ := json.Marshal(body)

err = ch.Publish(
  "",     // exchange
  "queue_name", // routing key
  false,  // mandatory
  false,  // immediate
  amqp.Publishing {
    DeliveryMode: amqp.Persistent,
    ContentType:  "application/json",
    Body:         jsonBody,
    Headers:      headers,

But I get this error:

Failed to publish a message: table field "argsrepr" value [%!t(string=arg1) %!t(string=arg2)] not supported

I'm using "github.com/streadway/amqp" library to talk with my rabbitmq node. It seems that "send task by name" is not implemented in this library.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    dongpang9573 dongpang9573 2018-06-17 13:25

    Here is an illustration of the symptoms. The fmt format string is apparently expecting boolean values.

    package main
    import "fmt"
    func main() {
        s := fmt.Sprintf("%t %t", "arg1", "arg2")
        t := fmt.Sprintf("%t %t", true, false)


    %!t(string=arg1) %!t(string=arg2)
    true false
    点赞 评论 复制链接分享