Reputation: 428
I have created one small genserver app referencing Etudes of Elixir AND working good, when i start the server and do GenServer.call..i get the desired data.
Meanwhile, my application is receiving messages from other producer as well, that has to be trapped, as right now it is visible on shell whenever my application receive any message like below.
iex(6)> subscription 0x7fdc83c0cdf0 ref 0x7fdc8403fc00
encode_message num 2
encode_message address topic://tryme
next/type PN_STRING
encode_message body alloc size 8192
encode_message formatted body "message body..."
write message sz: 130
Msg {message,#Ref<0.0.0.753>,
#{address => "topic://tryme",
body => "Enter some text here for the message body..."}}
AMQP Message received {message,#Ref<0.0.0.753>,
#{address => "topic://tryme",
body => "message body..."}}
How can i get this message in my app callback function to be send to database further. As far i can make out that i would receive this message in my handle_info as message not invoked using GenServer.call. But not sure how.
Upvotes: 2
Views: 228
Reputation: 51429
If your GenServer is receiving messages from another process, then you should be able to simply match them in handle_info/2. Try something like this:
def handle_info(msg, state) do
IO.inspect {:handle_info, msg}
{:noreply, state}
end
However, if nothing is printed after you add this line, it means that you are not receiving the messages you were expecting to.
Upvotes: 4