pedroassumpcao
Hi, I have a scenario with the following components:
Controller (a Phoenix one) → API (GenServer) → EventBus (GenEvent) → Worker (GenServer)
The applications are under an umbrella with the web layer, API and Messaging+Worker. For the web layer standpoint, I need to make sure of 2 things:
- API got my request
- job was done
But also for the web layer standpoint, the communication happens with the API only, how the API makes its work, it is an API concern.
One of my initial thoughts was having my API handle_call notifying the Messaging and listen to a message back, to then send the reply to the web layer. But I heard/read that is not good add a receive to listen general messages inside GenServer callbacks.
Other option is handling the worker messages in the API with handle_info, and send a message to the controller, but that will require having a receive to get the message in the controller side, what I don’t know if it is a good approach.
Any suggestions or comments?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 2 of 2 Posts
Azolo
Why not? I mean, it could be a code smell in some situations, but every time you do a
GenServer.callyou drop into areceiveblock to listen for the response.BUT, you could just not reply in the
API.handle_callcallback and have yourWorkerreply using theGenServer.replyfunction. It wouldn’t block your APIGenServerwaiting for a response, and still allows for a timeout using theGenServer.callsemantics.pedroassumpcao
Thanks, I think I will return the
handle_callwith{:noreply, new_state}and insidehandle_infouseGenServer.reply/2.