Hi there,
hope somebody could help with this problem:
We have a process that is interacting with a system of one of our partner companies. They use Stomp/Websocket for business transactions.
The Interaction should not overlap with other transactions, that’s why I decided to put it into a GenServer and use GenServer.call.
The transaction consists of sending a request to a stomp-topic and then waiting for a response another topic. We use Websockex to send and receive. My idea was that my GenServer.handle_call calls Websockex instance to send and Websockex instance will send a message to the Genserver when it receives a response on the other topic.
defmodule MyGenserver do
...
def handle_call(...) do
WebsockexInst.send_message(xxx)
receive do
{:response, ....} ->
react_on_response
end
end
end
But seems like Genserver does not like to receive arbitrary messages: XXX received unexpected message in handle_info/2: {:some_message}
The whole transaction is synchronous: HTTP-Request → RestApi → GenServer.call > RestApi → HTTP-Response
I think it would be easy if it would run asynchronous, but I don’t see a possibility for that.
So the question is: Is it possible to configure GenServer to be able to receive a message inside handle_call. Is there something I could change to sync my GenServer with the Websockex Process?
Cheers
Marcus