0
votes

I have two instances of cowboy server running which are connected to RabbitMQ. I am using gen_bunny as RabbitMQ client to connect to RabbitMQ.

I can consume the message to from rabbitMQ if using bunnyc:consume(). However for that I need to fire this method explicitly. What I want is to bind an event on cowboy so as soon as there is a message in the Queue it should automatically notify to cowboy.

Is it possible using gen_bunny or other erlang client?

2

2 Answers

2
votes

Dont know about gen_bunny, but with official erlang client you can subscribing to queue (look at http://www.rabbitmq.com/erlang-client-user-guide.html, "Subscribing To Queues" section)

As far as i understand, you need send messages from queue through WebSockets to clients. So you need subscribe to queue in process that communicate with client. And recieve messages in "receive ... end" or in handle_info (depends on realization)

ADDITION

I looked in gen_bunny sources... mochi/gen_bunny depends on mochi/amqp_client which provide amqp_channel:subscribe/3 (see https://github.com/mochi/amqp_client/blob/master/src/amqp_channel.erl#L177) you can use it for subscribing

0
votes

Got it worked ... After some tweaking in the bunnyc.erl source. Now, In init function i have added subscription function and in start_link function in bunnyc.erl passing the process id of my cowboy process so as soon as there is a message in the queue I can get it in websocket_info function of cowboy..