-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ feature ] pull() method to receive some messages without binding handler #24
Comments
How about code like this? There is no need to create new closure every time
|
Hello, The client, the stream and the consumer are correctly connected but the |
i have same isuue |
Hello @kuudr , Here is my /**
* Pop the next job off of the queue.
*
* @param string|null $queue
* @return \Illuminate\Contracts\Queue\Job|null
*/
public function pop($queue = null)
{
$stream = $this->getRootStream($this->getQueueName($queue));
$consumer = $stream
->getConsumer(config('queue.connections.nats.consumer'))
->setExpires(0)
->setIterations(1)
->setBatching(1);
$job = null;
$consumer->handle(
function ($message) use (&$job, $queue) {
// With NATS, non-filtered consumers may receive undesired messages from the stream,
// so we check the message conformity before returning a job instance to avoid errors
if (! $this->checkMessageIsKnownJob($message)) {
return;
}
$job = new NatsJob(
$this->container,
$message,
$this->connectionName,
$this->getQueueName($queue),
);
}
);
return $job;
} My issue was a misconfiguration of my consumer. I fixed it by creating a "pull" consumer with "Interest" retention policy on my stream. |
Internally library has some brood code where it's working with nats socket.
There is something like "bind handler to each message"... this callbacks could kill memory limit of any web server...
Usually in any applications worker does ITS OWN
while (true)
with configurable limits and timing.Method (Stream)->handle() does that, but there's no possibility to "ask for some messages" without binding handler. Even if handler is one line with
its still a handler that needs memory to store the \Closure object.
I mean that IMPOSSIBLE to wrap
while (true)
into ownwhile (true)
thats why you need to options like "setBatching()" and "setDelay", its not NATS stuff (but supported of course for lazy people and to debug/demonstration) - its business and server configuration.Actually any listening for better performance uses internally Observer pattern and works like
Instead of
Exactly because handle method with other settings could provide COLLECTION of messages and needs foreach then.
Also eventBus can parralel call handlers inside.
====
NATS is a fastest thing. Using many memory for processing - kills NATS bonuses.
I found this issue where trying to parralel connections with pcntl_fork(), garbage collector starts to delete so many callbacks from memory then i get error message "no handler for message", in case we CANNOT get message without a handler in this library.
The text was updated successfully, but these errors were encountered: