Code Monkey home page Code Monkey logo

Comments (5)

MattBearson avatar MattBearson commented on July 3, 2024 1

@stevenklar thank you, created a new one pull request few minutes ago

from laravel-amqp.

kitekkitek avatar kitekkitek commented on July 3, 2024

This is actually easy thing to do (tested on large scale for over 4 years now):
in Amqp.php:

private $prefetch_count = 1;


public function setPrefetchCount($prefetch_count)
{
    $this->prefetch_count = $prefetch_count;
}

public function consume($queue, Closure $callback, $properties = [])
{
    // If array, binding only first element, then the rest
    $routing_keys = [];
    if (is_array($properties['routing']))
    {
        $routing_keys = $properties['routing'];
        $properties['routing'] = array_shift($routing_keys);
    }

    $properties['queue'] = $queue;
    /* @var Consumer $consumer */
    $consumer = app()->make('Bschmitt\Amqp\Consumer');
    $consumer
        ->mergeProperties($properties)
        ->setup();

    // Binding queue with rest of routing keys
    foreach($routing_keys as $routing_key)
    {
        $consumer->channel->queue_bind($queue ?: $consumer->queueInfo[0], $consumer->getProperty('exchange'), $routing_key);
    }

    // Setting prefetch count
    $consumer->getChannel()->basic_qos(null, $this->prefetch_count, null);

    $consumer->consume($queue, $callback);
    Request::shutdown($consumer->getChannel(), $consumer->getConnection());
}

This adds prefetch count and option to pass routing_key as array of routings (multiple bindings per queue). Obviously like FlorinRo said setPrefetchCount() could also be an option prefetch_count for consumer.

from laravel-amqp.

MattBearson avatar MattBearson commented on July 3, 2024

@kitekkitek good solution, I made pretty the same but with 3 functions for prefetch_size, prefetch_count and a_global. Well, probably, @bschmitt should add it into master. This is a really good improvement.

from laravel-amqp.

stevenklar avatar stevenklar commented on July 3, 2024

@MattBearson if you would like to contribute feel free to open a pull request for this improvement.

from laravel-amqp.

stevenklar avatar stevenklar commented on July 3, 2024

Feature is done and merged into master. This will be also included in the next tagged release.
Thanks to @MattBearson for implementing and @fl0v for suggestion.

from laravel-amqp.

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.