Skip to content
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

How to access all the messages from the que #87

Open
anishansari opened this issue Sep 4, 2020 · 1 comment
Open

How to access all the messages from the que #87

anishansari opened this issue Sep 4, 2020 · 1 comment
Labels

Comments

@anishansari
Copy link

I am able to push the messages to the queue and I want to access all the messages and send the messages to the users dashboard or through SMS so I wanted to know how to get the content or all the message so that I can send them one by one to the users. Please help it is urgent.

Thank you

@liviublidar
Copy link

Hi @anishansari

You could call a function that just adds the messages to an array, then process it all in one go.

use App\Http\Controllers\Controller;
use Bschmitt\Amqp\Consumer;
use Bschmitt\Amqp\Amqp;
use Illuminate\Http\Request;
use PhpAmqpLib\Message\AMQPMessage;

class MyCoolController extends Controller {
  
    private $messageBatch = [];

    private function addMessageToBatch(AMQPMessage $message)
    {
        $this->messageBatch[] = $message;
    }
   
    private function sendMessagesViaSms()
    {
        //use $this->messageBatch here and do whatever with it
    }
 
    public function myCoolEntryPoint(Request $request, Amqp $consumer) 
    {
        $consumer->consume('myfancyqueue', function (AMQPMessage $message, Consumer $resolver) {
            $this->addMessageToBatch($message);
            $resolver->acknowledge($message); //ack message
            $resolver->stopWhenProcessed();
        });
        $this->sendMessagesViaSms();   
    }
}

Sorry if some of the formatting is wrong here, I don't have access to a proper editor at the minute ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants