Code Monkey home page Code Monkey logo

Comments (9)

whatyouhide avatar whatyouhide commented on July 17, 2024

FWIW, this is very useful for "sharding" queues as well, since RabbitMQ advises to have smaller queues. Broadway either lets you have many consumers connected to a single queue, or many consumers connected to a queue each (if you autodeclare the queue with queue: "").

from broadway_rabbitmq.

josevalim avatar josevalim commented on July 17, 2024

@whatyouhide i wonder if we should generalize your url/connection patch and allow it to returns a different queue too. This way you can have sharing or fault tolerance in the same API. We can complement the docs with more examples. WDYT?

from broadway_rabbitmq.

whatyouhide avatar whatyouhide commented on July 17, 2024

@josevalim or, we can generalize to make the whole options a function? I'm good with both things, but yeah this is easy enough to do if we make queue: fn index -> ... end

from broadway_rabbitmq.

josevalim avatar josevalim commented on July 17, 2024

We cannot make the whole options a function because some options may be handled by GenStage. One option is to have (merge_options: fun -> ... end), which we would call and merge into. WDYT?

from broadway_rabbitmq.

whatyouhide avatar whatyouhide commented on July 17, 2024

@josevalim hrm, merge_options could solve the :connection option as well as long as we do the merging as the first thing and then validate the options. Do you wanna go ahead with that route? I'm good both ways.

from broadway_rabbitmq.

josevalim avatar josevalim commented on July 17, 2024

Yup, let’s go this route then!

from broadway_rabbitmq.

ankopainting avatar ankopainting commented on July 17, 2024

Just wanted to thank you guys for turning this around so quickly!

It took me a little time to fully grok the solution, but for anyone reading this ticket here is an example;

    queues = ~w(messages messages2)
    queue_count = length(queues)

    Broadway.start_link(__MODULE__,
      name: __MODULE__,
      producer: [
          module: {
            BroadwayRabbitMQ.Producer, 
            queue: "",
            qos: [
              prefetch_count: 50
            ],
            merge_options: fn (index) -> 
              queue_name = Enum.at(queues, index)
              Logger.info(" connecting to queue #{queue_name}")
              [queue: queue_name] 
            end,
          },
          stages: queue_count
      ],
      processors: [
        default: [stages: 10]
      ],
      batchers: [
        elasticsearch: [stages: 1, batch_size: 400, batch_timeout: 500]
      ]
    )

from broadway_rabbitmq.

josevalim avatar josevalim commented on July 17, 2024

Awesome. I would only use Enum.fetch! instead of Enum.at so it raises if you give it less queues than stages.

from broadway_rabbitmq.

ankopainting avatar ankopainting commented on July 17, 2024

Great tip, thanks

from broadway_rabbitmq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.