package main
import (
"github.com/shaswata56/grabbitmq""github.com/shaswata56/grabbitmq/consumer""github.com/shaswata56/grabbitmq/helpers""github.com/shaswata56/grabbitmq/publisher""log"
)
funcmain() {
grabbitmq.SetRabbitMQUri("amqps://username:[email protected]/random")
pub:=publisher.GetPublisher()
pub.Connect()
err:=pub.CreateChannel("demoChannel")
helpers.FailOnError(err, "Failed to create channel on publisher")
err=pub.Publish([]byte("Hello RabbitMQ from demoChannel!!!"))
helpers.FailOnError(err, "Fail to publish message")
pub.Close()
con:=consumer.GetConsumer()
con.Connect()
err=con.CreateChannel("demoChannel")
helpers.FailOnError(err, "Failed to create channel on publisher")
messages, err:=con.Consume()
formessage:=rangemessages {
log.Println(string(message.Body))
ifmessage.Body!=nil {
con.Close()
break
}
}
}
Output:
2021/09/13 23:54:41 Hello RabbitMQ from demoChannel!!!
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].