polypush135

polypush135

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.

Showing Posts 1 to 4

akoutmos

akoutmos

Author of Build a Weather Station with Elixir and Nerves

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

polypush135 OP

Say I wanted to query a list of cities using Echo via fetching a list of cities from the repo on an interval. Where would you start with something like that? In my case there could be times there are no cities and othertimes the db is full of cities. Is this a correct use case for this?

akoutmos

akoutmos

Author of Build a Weather Station with Elixir and Nerves

I did something roughly similar to what you are describing in the 2 part series. I have a GenServer that publishes messages to RabbitMQ when certain conditions are met. You could easily modify my GenServer to make Ecto queries on a regular interval instead though. With the data that gets fetched from the DB, you can publish individual messages to RabbitMQ for each item of work that needs to take place. On the other side of that, Broadway will read those messages and process them.

polypush135

polypush135 OP

Thanks for the pointers, that helps.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews