go - Golang Rabbit MQ Fanout Exchange Multiple Consumers -
i publishing messages in fanout exchange java application. able receive message in multiple consumer in java. have 2 consumers in golang app 1 of consumer (alternatively ) receiving message (not both of them published message).
func handlemessagefanout1(){ conn := system.eltropyappcontext.rabbitmqconn channel, err := conn.channel() if(err!=nil){ log.println(err) } //forever := make(chan bool) deliveries,err := channel.consume( "example.queue", //queue "qw", true, false, false, false, nil) if(err!=nil){ log.println(err) } go func() { d := range deliveries { log.printf("message recived in fanout 1") log.printf("received message: %s", d.body) } }() //<-forever }
//2nd consumer
package consumer import ( "github.com/eltropy/shehnai/backend/golang/common-packages/system" log "github.com/sirupsen/logrus" ) func handlemessagefanout2() { conn := system.eltropyappcontext.rabbitmqconn channel, err := conn.channel() if (err!=nil) { log.println(err) } //forever := make(chan bool) deliveries, err := channel.consume( "example.queue", //queue "q2", true, false, false, false, nil) if (err!=nil) { log.println(err) } go func() { d := range deliveries { log.printf("message recived in fanout 2") log.printf("received message: %s", d.body) } }() //<-forever }
i using https://github.com/streadway/amqp library rabbit mq.
on channel type, before publish, declare exchange this:
err = channel.exchangedeclare( "example.queue", // name "fanout", // type true, // durable false, // auto-deleted false, // internal false, // no-wait nil, // arguments )
Comments
Post a Comment