48 lines
879 B
Go
48 lines
879 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"time"
|
||
|
|
||
|
"git.faercol.me/management-platform/events/config"
|
||
|
amqp "github.com/rabbitmq/amqp091-go"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
fmt.Println("coucou from client")
|
||
|
|
||
|
fmt.Println("connecting to RMQ")
|
||
|
conf := config.RMQConfig{
|
||
|
Host: "localhost",
|
||
|
Port: 5672,
|
||
|
User: "guest",
|
||
|
Password: "guest",
|
||
|
}
|
||
|
|
||
|
con, err := amqp.Dial(conf.URL())
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
defer con.Close()
|
||
|
|
||
|
ch, err := con.Channel()
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
q, err := ch.QueueDeclare("example", false, false, false, false, nil)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||
|
defer cancel()
|
||
|
|
||
|
if err := ch.PublishWithContext(ctx, "", q.Name, false, false, amqp.Publishing{ContentType: "text/plain", Body: []byte("test message")}); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
fmt.Println("done")
|
||
|
}
|