Non-static method 'consume' should not be called statically
Opened this issue · 1 comments
shwetatyagi22 commented
I am using below function to consume messages from rabbitmq queue.
My IDE is giving me a warning for consume method Non-static method 'consume' should not be called statically
Amqp::consume('queue-name', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
$resolver->stopWhenProcessed();
});
liviublidar commented
Hi @shwetatyagi22 ,
If you're using this with Laravel, the Consumer class can be injected to your controller function as it's registered as a provider.
This should be equally injectable in a command.
use App\Http\Controllers\Controller;
use Bschmitt\Amqp\Consumer;
use Bschmitt\Amqp\Amqp;
use Illuminate\Http\Request;
class MyCoolController extends Controller {
public function myCoolEntryPoint(Request $request, Amqp $consumer) {
$consumer->consume('myfancyqueue', function (AMQPMessage $message, Consumer $resolver) {
$this->doStuffToMyMessage($message);
$resolver->acknowledge($message); //ack message
$resolver->stopWhenProcessed();
});
}
}