basis-company / nats.php

nats jetstream client for php
137 stars 34 forks source link

Call to undefined method Basis\Nats\Consumer\Consumer::getQueue() #101

Open ljfreelancer88 opened 1 week ago

ljfreelancer88 commented 1 week ago

Hi, I got undefined method when using the 1 & 2 approaches below.

Uncaught Error: Call to undefined method Basis\Nats\Consumer\Consumer::getQueue() 
# Approach 1
$queue = $post_notifier_consumer->setBatching(50)->create()->getQueue();
$messages = $queue->setTimeout(1)->fetchAll(100);

$recipients = [];
foreach ($messages as $message) {
    $recipients[] = (string) $message->payload;
}
var_dump($recipients);
# Approach 2
$post_notifier_consumer->create();
$queue = $post_notifier_consumer->getQueue();
while ($msg = $queue->next()) {
    $postNotification = json_decode($msg, true);
    var_dump($postNotification);
    /*
    if (someConitionToStop) {
        $client->unsubscribe($queue);
        break;
    }
    */
}

These are both fine

# Approach 3
$post_notifier_consumer->handle(function ($msg) {
    var_dump($msg);
});
# Approach 4
$post_notifier_consumer
    ->setBatching(2) // how many messages would be requested from nats stream
    ->setIterations(3) // how many times message request should be sent
    ->handle(function ($msg) {
        var_dump($msg);
    });