Revisiting the Producer
We'll update the consumer demand in our scraper project and then build an API to send requests to scrape pages.
We'll cover the following...
Update consumer demand
Now, for our scraper
project, let’s lower the demand to something more suitable:
Press + to interact
#scraper/lib/page_consumer.exdef init(initial_state) doLogger.info("PageConsumer init")sub_opts = [{PageProducer, min_demand: 0, max_demand: 3}]{:consumer, initial_state, subscribe_to: sub_opts}end
With min_demand
set to 0
and max_demand
set to 3
, we ensure that the consumer takes at least one event when available, up to 3 at a time. However, our producer still has to supply the consumers with events, and right now, it doesn’t do anything. Let’s fix this.
Going back to PageProducer
, we have implemented the handle_demand/2
callback to respond to demand and produce events. Remember that handle_demand/2
is always called when the producer ...