func main() {
	isProducer := flag.Bool("producer", false, "Is this process a producer?")
	flag.Parse()

	logger := lager.NewLogger(fmt.Sprintf("Process-%d", os.Getpid()))
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	creds := rabbitmq.AMQPCredentials{
		Host:     "localhost",
		Port:     5672,
		Username: "******",
		Password: "******",
	}
	queue := "producers-consumers"

	if *isProducer {
		sender, err := rabbitmq.NewSender(creds, queue)
		mustNot(err)
		ch, err := gofigure.OutboundChannel(sender)
		mustNot(err)
		logger.Info("got-write-channel")

		ch <- "Hello consumers"
		logger.Info("sent-message")
	} else {
		receiver, err := rabbitmq.NewReceiver(creds, queue)
		mustNot(err)
		ch, err := gofigure.InboundChannel(receiver)
		mustNot(err)
		logger.Info("got-read-channel")

		data := <-ch
		logger.Info(data.(string))
		logger.Info("received-message")
	}

	logger.Info("done")

	select {}
}
Exemple #2
0
func main() {
	creds := rabbitmq.AMQPCredentials{
		Host:     "localhost",
		Port:     5672,
		Username: "******",
		Password: "******",
	}
	queue := "hello"

	receiver, err := rabbitmq.NewReceiver(creds, queue)
	if err != nil {
		log.Fatal(err)
	}

	ch, err := gofigure.InboundChannel(receiver)
	if err != nil {
		log.Fatal(err)
	}

	for {
		data := <-ch
		fmt.Println(data)
	}
}