package main
import (
"fmt"
"github.com/streadway/amqp"
"log"
"time"
)
func main() {conn, err := amqp.Dial("amqp://user:password@host:ip/vhost")
if err != nil {log.Fatalf("%s", err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {log.Fatalf("%s", err)
}
defer ch.Close()
body := "Hello World!" + time.Now().Format("2006-01-02 15:04:05")
fmt.Println(body)
ch.QueueDeclare(
"j_test_delay", // name
false, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
err = ch.Publish(
"", // exchange 这里为空则不抉择 exchange"j_test_delay", // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "text/plain",
Body: []byte(body),
})
}
package main
import (
"fmt"
"github.com/streadway/amqp"
"log"
"time"
)
func main() {conn, err := amqp.Dial("amqp://user:password@host:ip/vhost")
if err != nil {log.Fatalf("%s", err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {log.Fatalf("%s", err)
}
defer ch.Close()
body := "Hello World!" + time.Now().Format("2006-01-02 15:04:05")
fmt.Println(body)
ch.QueueDeclare(
"j_test_delay", // name
false, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
err = ch.Publish(
"", // exchange 这里为空则不抉择 exchange"j_test_delay", // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "text/plain",
Body: []byte(body),
})
}