1.新建一个vhost :

  rabbitmqctl add_vhost test

  2.新建一个用户:

  rabbitmqctl add_user news news

  3.对这个news用户增加test host的权限:

  rabbitmqctl set_permissions -p test news ".*" ".*" ".*"

  4.代码中进行连接:

  

   conn, err :=amqp.Dial("amqp://news:news@127.0.0.1:5672/test")
    Ch, err = conn.Channel()    
    //申明队列
    Queue, err = Ch.QueueDeclare(
            "bigdata",
            false,
            false,
            false,
            false,
            nil,
    )
    //发布消息
    err := Ch.Publish(
        "",
        Queue.Name,
        false,
        false,
        amqp.Publishing{
            Body: b,
        })    

  5.查看消息队列中的消息:

  rabbitmqctl list_queues -p bigdataSync