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
			ceBinPath = RabbitMQCeBinPath
		})

		It("works", func() {
			creds := rabbitmq.AMQPCredentials{
				Host:     "localhost",
				Port:     5672,
				Username: "******",
				Password: "******",
			}
			queue := "hello"

			sender, err := rabbitmq.NewSender(creds, queue)
			Ω(err).ShouldNot(HaveOccurred())

			ch, err := gofigure.OutboundChannel(sender)
			Ω(err).ShouldNot(HaveOccurred())

			ch <- "hello"
			Eventually(stdout, "2s").Should(gbytes.Say("hello"))
		})

		It("sends ints", func() {
			creds := rabbitmq.AMQPCredentials{
				Host:     "localhost",
				Port:     5672,
				Username: "******",
				Password: "******",
			}
			queue := "hello"