Node.js SQS to FastCGI worker/daemon/background process
Welcome to this silly little utility program. It provides an intermediary link between an SQS message queue and a backend FastCGI system. It is very simple. All you do is push a message to an SQS queue and this program will receive it and forward it to a FastCGI server, presumably PHP-FPM. Just plop this handy little program on the server with PHP-FPM, change some of the settings in the source code and run it. The message retrieved from SQS is POSTed to FastCGI. Given that SQS allows you to send a million messages per month, this could be a very cheap, simple, means of having a worker queue in PHP without having any infrastructure to manage.
Also, I’m not a node.js developer. If I totally messed this up feel free to rewrite it with a pull request.
Don’t forget to
npm install
Then
node bin/start.js
There is no PHP library to use it. If you want to build your own plumbing for making it work you can. You could do something as simple as having this payload:
{
"job": "Jobs\WriteMessage",
"payload": "This is a message"
}
push to this bootstrap file
namespace Jobs {
class WriteMessage {
public function execute($message) {
file_put_contents('/tmp/message', $message);
}
}
}
$content = file_get_contents('php://input');
$data = json_decode($content, true);
$class = $data['job'];
$obj = new $class();
$obj->execute($data['payload']);
or thereabouts. I don’t know. I wrote that code without testing it. But that’s how simple it would be.
You can get it on GitHub
Have fun.
Comments
No comments yet...