running laravel queue with multiple database - php

I have Laravel 5 project. This is multi-tenant project, so I have one folder project with multiple databases.
When I use php artisan queue:listen, it only works with the current database setup. I use the database queue driver, so each tenant has their own notifications table. How do I setup a queue listener to check all database jobs?

If you want to continue using the database driver, I would suggest setting up another database that contains all your queued jobs and failed jobs.
Although it is not in the config or mentioned by the documentation, after taking a look at the code, it looks like you should be able to add a connection parameter to your queue configuration, and then the queue will interact with the database specified by that connection.
So, in your config/database.php, define a new connection for your queue database:
'connections' => [
// your existing connections
'queue' => [
'driver' => 'mysql',
'database' => 'your-queue-database',
// rest of connection information (host, port, etc)
],
],
Then, in your config/queue.php, tell your database queue to use your new connection:
'connections' => [
'database' => [
'driver' => 'database',
'connection' => 'queue', // connection name from database config
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
]
The other option would be to move to another queue driver. Setup redis, sqs, or beanstalk.

Related

How to change database queue connection in laravel queue

Im currently using laravel queue and works perfectly fine when I only have 1 database connection. But now that I need 2 database connection (one for local, one for production). How can I set the local as my connection for my database queue?
What I tried
queue.php
'database' => [
'connection' => 'mysql_local',
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
'after_commit' => false,
],
So I've added a connection key but queue still using my other connection.
.env
DB_CONNECTION=mysql
DB_HOST=PRODUCTIONIP
DB_PORT=3306
DB_DATABASE=core3
DB_USERNAME=adm
DB_PASSWORD=secret1234
DB_CONNECTION_LOCAL=mysql_local
DB_HOST_LOCAL=127.0.0.1
DB_PORT_LOCAL=3306
DB_DATABASE_LOCAL=core3
DB_USERNAME_LOCAL=root
DB_PASSWORD_LOCAL=secret
I need to use the mysql_local connection, but no idea on how to use it.

Typo3 with MSSQL [duplicate]

I tried to install TYPO3 (8.7.7) on my Webserver (IIS) and I'd like to use my SQL Server instead of MySQL.
I found lots of instructions how to make this (on typo3.org and other websites) but none of these worked for me.
I found out, that I must install two extensions before I start the installation (ADOdb & DBAL). Probably there is my fault.
Can anybody explain step by step how to install these extensions before the TYPO3 installation?
I'm using the following configuration to successfully run TYPO3 on SQL Server on my local windows machine:
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf-8',
'dbname' => 't3',
'driver' => 'sqlsrv',
'host' => 'localhost',
'password' => 'yourPassword',
'port' => 1433,
'user' => 'sa',
],
],
],
It's a bit complicated to set up with the installer as it is not yet "clickable". What you can do is call the install script and when it's asking you to configure the database connection you go to your file system and manually add the config section above (with your connection params of course) in the LocalConfiguration.php file.
Then reload the installer - which should now recognize the configured database connection and let you go to the last step where you can import / create the base tables and data.
Note: At the moment I know of two bigger areas where SQL Server is still a problem with TYPO3 8.7 - that's workspaces and database compare. The last one means that after you have existing data in your SQL Server tables won't let you alter them via the TYPO3 database compare tool - you have to change tables manually if you need to.
Find a gist of the table create statements on https://gist.github.com/psychomieze/9570ea1f578aee7a1fbb68c3240a21c8
With 8.7, Doctrine DBAL has been integrated into the core and ADOdb & DBAL sysexts have been removed as there is no need anymore.
Take a look at the documentation of Doctrine DBAL http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html and it should fit perfectly to the configuration of the DB in `LocalConfiguration.php``
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf8',
'dbname' => 'typo3',
'driver' => 'mysqli',
'host' => 'mysql',
'password' => 'dev',
'port' => 3306,
'user' => 'root',
],
],
],
Now my Typo3 is working.
I solved my problem a little bit complicated.
I made a test environment and installed Typo3 with MySQL.
Then I copied the database with the "Microsoft SQL Server Migration Assistant 7.6 for MySQL"
(https://www.microsoft.com/en-us/download/details.aspx?id=54257) to my main environment.
After that I copied all the created folders (typo3conf, typo3temp etc.) to my main environment
and edited the databaseconnection in the LocalConfiguration.php file like Georg Ringer proposed.
When I am installing Typo3 and MSSQL next time I will do it like susi proposed.
Thanks for your help.

Redis server connection error in laravel v4.2

Hi I working in laravel v4.2. Now I want to send push notifications to users in queue so for this purpose I use redis server for queue push notifications. But the problem is that I want use the redis server of of other server instead of home/local server. Is there any solution to solve this problem. Below is my queue.php file configuration that I am using
'redis' => array(
'driver' => 'redis',
'queue' => 'default',
'cluster' => true,
'default' => array(
'host' => '192.168.1.244',
'port' => 6379,
'database' => 0,
'password' => ''
),
If I use my own pc IP address then I receice queue notification but when I try to use the other pc redis server then I receive following error in exception
Connection refused [tcp://127.0.0.1:6379]
Please let me know if anyone know that how to cofigure or user redis server remotely.
Thank you
I found the issue issue in my code I was doing configuration in queue.php instead of database.php file. So when I change the host in database.php file then I become able to work with redis server.

No connection left in pool for cluster slots of Redis cluster when using PRedis library in Lumen

My team have one project using Lumen(which is a micro framework based on Laravel). We use Predis to connect our Redis cluster and run some queue job on it. But sometimes(we can't re-produce) system will throw "No connections left in the pool for CLUSTER SLOTS in .." exception
[2017-08-17 14:05:35] bookmark.ALERT: Predis\ClientException: No connections
left in the pool for `CLUSTER SLOTS` in
....../vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php:232
Stack trace:
#0 ....../vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(260):
Predis\Connection\Aggregate\RedisCluster->queryClusterNodeForSlotsMap(NULL)
#1 ....../vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(560):
Predis\Connection\Aggregate\RedisCluster->askSlotsMap()
...
We have investigated for a long time. We think the problem might be in the Predis library of Laravel, and the way it maintain connection pool. It might because Redis cluster close connection in some reason but Predis library didn't reopen the connection when it try to make connection.
and here's our cluster setting structure:
'redis' => [
'client' => 'predis',
'clusters' => [
// Setting for Queue
'default' => [
'options' => [ 'cluster' => 'redis' ],
[
'host' => 'xxx',
'password' => 'xxx',
'port' => 'xxx',
'timeout' => 0.15,
'read_write_timeout' => 0.15
],
[
'host' => 'xxx',
'password' => 'xxx',
'port' => 'xxx',
'timeout' => 0.15,
'read_write_timeout' => 0.15
],
...
]
]
]
Any one have idea on it? Thank you very much!
Because you only see these exceptions intermittently, the timeout values in your 'redis' configuration may be too low. I can only guess that bursts of traffic on the network between the PHP and Redis servers slows down communication enough to cause client connections to time out (after 0.15 seconds, as configured).
The Predis client throws No connections left in the pool for `CLUSTER SLOTS` when it fails to fetch the slots map from all of the configured Redis hosts (because, presumably, they all timed-out). You can reproduce this behavior by setting a really small timeout value like 0.0001.
Try increasing the timeout values and consider monitoring the network for issues that cause latency.

How to use other QUEUE_DRIVER than default in laravel 5.1 queue?

I my apps in queue.php I have set:
'default' => env('QUEUE_DRIVER', 'rabbitmq'),
this is proper for most jobs in app, but i would like to use also 'database' driver and add jobs to postgresql db.
It works of course if I change default setting to:
'default' => env('QUEUE_DRIVER', 'database'),
But then rabbitmq doesn't work.
I don't know how to use other 'QUEUE_DRIVER' than default?
I would like to use both for different jobs.
It doesn't works:
php artisan queue:listen database
because there is nothing there.
I will be glad for any help.
From https://github.com/illuminate/queue/blob/master/README.md
use Illuminate\Queue\Capsule\Manager as Queue;
$queue = new Queue;
$queue->addConnection([
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
]);
// Make this Capsule instance available globally via static methods... (optional)
$queue->setAsGlobal();
In this way you should be able to create another queue object than the default one (name it $rabbitQueue for example), using a custom connection / driver. All subsequent calls to $rabbitQueue->push() to this instance will push messages to RabbitMQ. Other $queue->push() still using default connection.

Categories