Is it possible to start queues running synchronously with Laravel

I'm trying to set up an API system that communicates with multiple workers synchronously in Laravel. I am using Laravel 5.4 and would like to use its functionality if possible without too many plugins if possible.

What I meant is two servers. The first one with a Laravel instance - lets call it APP - receive and respond to requests from user and user. Second, there are different workers at work, each of which is a Laravel instance. This is how I see the workflow:

  • APP receives request from user
  • APP queues the request
  • The workers look for jobs in the queue and eventually find them.
  • Employee authorizes work
  • The workers' responses to the APP OR APP somehow figure out that the job is cleared.
  • APP sends a response to the user

My first idea was to work with queues and beanstalkd. The problem is that it all works asynchronously. Is there a way for the APP to wait for the result of one of the workers?

After some more research, I came across Goose. Will this be the way to go?

EDIT: More information on the project. I'm talking about Restful API. For example. the user submits a request in the form " https: //our.domain/article/1 " and their API token in the header. What the user receives is a JSON string such as {"id": 1, "name": "article_name", etc.}

The reason for using both sides is twofold. On the one hand, different workers are used. On the other hand, we want all API logic to be as secure as possible. When hack attack, only the APP side will be compromised.

Maybe I'm making it harder with queues and stuff? If you have a better approach to meeting those same goals, this will certainly help.

+1


source to share


1 answer


I know your question was how you can run this synchronously, I think the problem you are having is that you cannot update the first server after shutting down. The way you could achieve this is through the broadcast.

I did something similar with downloads in our application. We are using a Redis queue, but beanstalk will do the same job. Also, we are using a pusher that uses sockets that the user can subscribe to and looks great.



  • The user downloads the web application by connecting to the push server.
  • User uploads the file (at this point you can show something to inform the user that the file is being processed)
  • The worker sees that there is a file
  • The workflow processes the file
  • Work triggers and events on run or fail
  • This event is sent to the pusher server
  • Since the user is listening on the push server, the event is received via javascript
  • You can now show the popup or update the table using javascript (works even if the user navigated through).

We used a pusher for this, but you can use redis, beanstalk and many other solutions for this. Read about Broadcasting Events in the Laravel documentation.

+1


source







All Articles