Push to a different beanstalkd server - laravel

I have set my config to use my local beanstalkd server:
'beanstalkd' => array(
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
)
How do I push jobs to another beanstalkd server?
Queue::push(function($job)
{
// This pushes to local beanstalkd
});
Queue::pushToRemoteBeanstalkdInstance(function($job)
{
// ?
});

You have to make an extra config in the queue config file, so it will look something like this:
'connections' => array(
'beanstalkd' => array(
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
),
'beanstalkd_remote' => array(
'driver' => 'beanstalkd',
'host' => 'remotehost',
'queue' => 'default',
)
)
If the default is set to "beanstalkd" you can keep calling it the normal way.
If you want to use the remote queue simply define the connection in the call like:
Queue::connection('beanstalkd_remote')->push(function($job)
{
// This pushes to remote beanstalkd
});

Related

cakephp3 redis not configured properly

I am having a super hard time getting redis to be configured. It was working, but I upgraded my servers and composer updated- now I getting "redis is not configured correctly"
define('_CACHE_SERVER', '*********.cache.amazonaws.com:6379');
'_cake_core_' => [
'className' => 'Redis',
'servers'=> [ _CACHE_SERVER ],
'prefix' => 'mrg_cake_core_',
'serialize' => 'php',
'duration' => '+2 minutes',
],
I have written a blank php and connected to redis with just simple $redis = new Redis(); and got $redis->lastSave(); Seems like something changed in CAKE. Very confused.
Thank you ndm, I changed the config to:
define('_CACHE_SERVER', '************.cache.amazonaws.com');
'_cake_core_' => [
'className' => 'Redis',
'host' => _CACHE_SERVER,
'port' => 6379,
'prefix' => 'myapp_cake_core_',
'duration' => '+1 years',
'url' => env('CACHE_CAKECORE_URL', null),
],

Configure Redis Sentinel in Laravel 5.5

How to configure the Redis sentinel? Redis can be configured in stand alone easily using laravel configs but when using sentinel how to configure is not documented anywhere?
There is one similar question asked on redit: but no help.
In Laravel 5.5 one can do it like this:
Reference: https://github.com/laravel/framework/pull/18850#issue-116339448
database.php:
'redis' => [
'client' => 'predis',
// Keep Default as is you want to use both redis and sentinel for different service(cache, queue)'
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
// Create a custom connection to use redis sentinel
'cache_sentinel' => [
// Set the Sentinel Host from Environment (optinal you can hardcode if want to use in prod only)
env('CACHE_REDIS_SENTINEL_1'),
env('CACHE_REDIS_SENTINEL_2'),
env('CACHE_REDIS_SENTINEL_3'),
'options' => [
'replication' => 'sentinel',
'service' => 'cachemaster'),
'parameters' => [
'password' => env('REDIS_PASSWORD', null),
'database' => 0,
],
],
],
],
```
Specify the redis connection in your service where you want to use. example if cache needs redis sentinal can create new cache connection to use the above sentinal connection like this:
'stores' = [
//Keep default too as is
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
// create own cache connection
'sentinel_redis' => [
'driver' => 'redis',
'connection' => 'cache_sentinel',
],
And in Laravel app you can easily use via Cache Facade:
Cache::store('sentinel_redis')->get('key');

Work with mysql database in Laravel 4.2

I am new to Laravel used this https://github.com/msurguy/laravel-facebook-login link to work with facebook login in Laravel. I have setup all the things but i
got following errors when establishing database connection :
Type error: Argument 1 passed to
Illuminate\Redis\Database::__construct() must be of the type array,
null given, called in
C:\wamp64\www\laravel-facebook-login-master\vendor\laravel\framework\src\Illuminate\Redis\RedisServiceProvider.php
on line 23
I want to run simple mysql database. Below is my database.php code:
return array(
'fetch' => PDO::FETCH_CLASS,
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'facebookdb',
'username' => 'root',
'password' => '',
'port' => '3603',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
),
'migrations' => 'migrations',
);
Any suggestion/help will be highly appreciated.
You are missing the definition for your redis connection in that connections array, something like this will help:
'redis' => array(
'host' => env('REDIS_HOST', 127.0.0.1),
'port' => env('REDIS_PORT', 6379),
'password' => env('REDIS_PASSWORD', null),
'database' => env('REDIS_DATABASE', 0)
)
Make sure that you add the corresponding entries in your .env file if your redis connection settings differ from the default values above.

Laravel and Multiple SQS (queue) configs

Is there a method on the Queue class that can specify a specific connection as defined in the queue config? There's a similar option for MySql, where you can define 'mysql2', and then call:
DB::connection('mysql2')->table('etc')->get();
Is there a similar option for queues?
Something like:
Queue::connection('sqs2')->push('MyQueue', array('message' => $message));
Apparently I answered my own question above without even realizing it. You can have multiple queues and specify which one you want to push the message to by using a connection method.
Here's what my partial config looks like for anybody that's interested:
'default' => 'sqs',
'connections' => array(
'sync' => array(
'driver' => 'sync',
),
'beanstalkd' => array(
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
),
'sqs' => array(
'driver' => 'sqs',
'key' => 'xxxxxxxxxxxx',
'secret' => 'yyyyyyyyyyyyyy',
'queue' => 'https://sqs.us-west-2.amazonaws.com/zzzzzzzzz',
'region' => 'us-west-2',
),
'sqs2' => array(
'driver' => 'sqs',
'key' => 'uuuuuuuuuuuuu',
'secret' => 'vvvvvvvvvvvvvvvv',
'queue' => 'https://sqs.us-west-2.amazonaws.com/wwwwwwwwwww',
'region' => 'us-west-2',
),
You only configure one connection to SQS, then unlike other drivers like redis or database, if you want to send a job in a different queue name, that queue should exist previously, create it in the amazon console or with an SDK/api, then pass it when dispatching the job like this:
dispatch(new MyJob)->onConnection('sqs')->onQueue('https://sqs.us-east-1.amazonaws.com/{account_id}/{queue_name}');
In this way you only configure one connection, and have multiple queues in that connection
For last for proccesing the Job like in egekhter response,
php artisan queue:work sqs --queue='https://sqs.us-east-1.amazonaws.com/{account_id}/{queue_name}'
you also can configure multiple connections but it seems unnecessary since all of them are in the same account and credentials, and it seems the perfect use case for multiple queues in the same conexion.

How to use the CLI Options for Artisan to execute on a different Laravel Environment

I am installing the migrate scripts for the first time on my application.
What I wish to do is use the configuration under /config/test/database.php to run my migrate installation scripts.
My entry on paths.php is the following
$environments = array(
'test' => array('http://test.*'),
'local' => array('http://localhost.*')
);
My entry on /application/config/test/database.php
return array(
'connections' => array(
'mysql' => array('driver' => 'mysql',
'host' => 'localhost',
'database' => 'new_db',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'prefix' => '')
),
);
and /application/config/database.php
return array(
'connections' => array(
'mysql' => array('driver' => 'mysql',
'host' => 'localhost',
'database' => 'default_db',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'prefix' => '')
),
);
Every time I run php artisan migrate:install --env=test it always installs on the DB defined on /application/config/database.php and not using the configuration from /application/config/test/database.php.
Appreciate if someone could help me fix this issue.
I figured it out myself. Am not sure if this is something that has been documented in Laravel for multiple environment. An additional parameter was required on the environment definition on the paths.php
$environments = array(
'test' => array('http://test.*','MY_COMPUTER_NAME'),
'local' => array('http://localhost.*')
);
Now, running php artisan migrate:install --env=test correctly executes the migration scripts on the DB configuration defined on /application/config/test/database.php.
Hope this helps others

Resources