polypush135
Trying to better understand broadway
Was reading How to Use Broadway in Your Elixir Application | AppSignal Blog
and wanted to get a better understanding of how the incoming messages can be triggered and managed.
Right out the box with this tut, it uses a WorldTemp.CityProducer example that I have a hard time understanding. There are two cases of handle_demand, one is for when demand > length(state) the other for when this is not true.
First: What does demand here represent? It starts with a default value of 10. Where does this value come from and what does it represent? What should I read to get a betting understanding of this value?
Second: The city list function is a static list. What if I wanted to do an ecto query and get a list of rows that should be processed. Is this where that request would look up said rows?
I guess so far the producer is the most confusing part to me.
Edit: I think I figured out my disconnect. This module is a GenStage. GenStage — gen_stage v1.3.2 and not directly related to Broadway.
Time to go learn some GenStage I guess.
Most Liked
akoutmos
Author of the article here and good questions!
The reason for the two different handle_demand functions (one with the guard and one without) is because our GenStage producer effectively creates an infinite list of cities. That first function with the guard ensures that there are enough cities in the list to satisfy the incoming demand by adding more items to the list. The demand in this case represents what the downstream Broadway consumers are requesting from this producer.
While you can use GenStage as a producer, in production you most often would use Broadway with something like RabbitMQ or Kafka. I chose GenStage as a producer for that article mostly to keep the length of the article within reason. I have a more in depth 2-part series tutorial on my personal blog that leverages RabbitMQ, Broadway, and Ecto:
polypush135
Thanks for the pointers, that helps.
Popular in Questions
Other popular 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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








