1

I am newbie to erlang but managed to get the ActiveMQ talking to my erlang shell using qpid pronton c library as, which is working well and i am getting messages from queue itself on my erlang shell and vice versa.

qpidpn:subscribe("amqp://localhost/topic://xxx").
qpidpn:publish(#{address => "amqp://127.0.0.1/topic://xxx", body => "hello"}).

Now, i want to implement the same above stated code using .erl file with some function getting invoked everytime we have new message on the queue and i can take further action of returning the same to origin.

StackUser
  • 141
  • 1
  • 1
  • 8

2 Answers2

1

You can implement gen_server, as seems the messages are coming from some MQ. So, you can get the messages in handle_info. Once there you can do whatever you want to do with them.

Coder
  • 428
  • 4
  • 16
0

Well, it all depends on how your subscriber is implemented (is it another process, TCP listener, do you use gen_event behaviour, does it decode any data for you .... ).

Since you are using AMQP protocol for communication, you could use RabbitMQ as client. You would get whole AMQP implementation (with all responses to your broker), and some model for getting messages or subscribing to channels. Code-base is mature, whole project is stable, and most of logic is written for you, so I would strongly recommend using this approach.

The "invoked everytime we have new message on the queue" is somewhat explained in subscibe to que section.

mpm
  • 3,534
  • 23
  • 33
  • Thanks mpm but there is a requirement so can not use any other MQ. But tried to work on the code/module which can do the job of reflecting the messages coming from producer to logic server but didn`t got much out of that. – StackUser Jun 30 '14 at 16:02
  • Than again it would depend on how you are bind C code with Erlang (NIF, driver or Port). Please give us little more information. And I could recommend going trough http://www.erlang.org/doc/tutorial/users_guide.html – mpm Jul 02 '14 at 11:41
  • And once again, I would suggest using RabbitMQ. You would be using it only as a client to your ActiveMQ broker, without any change in you AMQP protocol. It should not look any different from outside of Erlang. – mpm Jul 02 '14 at 11:43
  • Thanks mpm, Ok i`ll try to give more detailed information now. First thing is that i can not use any other MQ for now being some requirement only. Secondly, when using iex shell using i managed to use proto c function via qpid-erlang library like iex --erl "-pa ebin -env DYLD_LIBRARY_PATH ./priv -env LD_LIBRARY_PATH ./priv -s qpidpn start". So, now if i want to make new Elixir/Erlang app suppose i want to use that same command to access the library function from my bash script. That means to use already compiled libraries in Elixir to access proton c library functions. – StackUser Jul 03 '14 at 09:28