I have found famous library for using RabbitMQ in Laravel.
In configuration config/queue.php
I can specify only one exchange and queue name.
Does it
support multiple exchanges?
For future people who will search the answer for this question.
There is one(bad) way to add multiple exchanges. You have to duplicate rabbitmq connection with new exchange and when you will want to publish the message to new exchange, you will just change connection.
This is a very ugly way, but i didn't another one. Laravel queue doesn't provide a method to change the exchange, but there is the method onConnection what you help you.
Here is a simple example
'conn_one' => [
'driver' => 'rabbitmq',
'queue' => env('RABBITMQ_QUEUE', 'default'),
'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,
'hosts' => [
[
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
'port' => env('RABBITMQ_PORT', 5672),
'user' => env('RABBITMQ_USER', 'guest'),
'password' => env('RABBITMQ_PASSWORD', 'guest'),
'vhost' => env('RABBITMQ_VHOST', '/'),
],
],
'options' => [
'ssl_options' => [
'cafile' => env('RABBITMQ_SSL_CAFILE', null),
'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
],
'queue' => [
'job' => VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob::class,
'exchange' => 'exchange_two',
'exchange_type' => 'fanout',
],
],
],
'conn_two' => [
'driver' => 'rabbitmq',
'queue' => env('RABBITMQ_QUEUE', 'default'),
'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,
'hosts' => [
[
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
'port' => env('RABBITMQ_PORT', 5672),
'user' => env('RABBITMQ_USER', 'guest'),
'password' => env('RABBITMQ_PASSWORD', 'guest'),
'vhost' => env('RABBITMQ_VHOST', '/'),
],
],
'options' => [
'ssl_options' => [
'cafile' => env('RABBITMQ_SSL_CAFILE', null),
'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
],
'queue' => [
'job' => VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob::class,
'exchange' => 'exchange_two',
'exchange_type' => 'fanout',
],
],
],
Use
ExampleJob::dispach($data)->onConnection('conn_one');
ExampleJob::dispach($data)->onConnection('conn_two');
Or another ugly way could be to set config like this
Config::set('queue.connections.rabbitmq.options.queue.exchange', 'exchange_two');
before dispatching the job to the new exchange. In this way you dont have to create a duplicate connection just setting new exchange name before dispatching the job to the new exchange.
Related
I have redis cluster config, in laravel 5.8, with one node and two shards.
I need to add prefix for session and cache, but now I have all keys without prefix.
Tis is my laravel database config:
'redis' => [
'client' => 'predis',//I also tried phpredis, same problem
'cluster' => env('REDIS_CLUSTER_ENABLED', true),
'clusters' => [
'default' => [
[
'host' => 'node-endpoint-1',
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 0),
'options' => [
'prefix' => 'help_session:',
]
],
[
'host' => 'node-endpoint-2',
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 0),
'options' => [
'prefix' => 'help_session:',
]
],
],
'cache' => [
[
'host' => 'node-endpoint-1',
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 0),
'options' => [
'prefix' => 'cache:',
]
],
[
'host' => 'node-endpoint-2',
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 0),
'options' => [
'prefix' => 'cache:',
]
]
],
],
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
],
],
I cannot find a different configuration. Is it possible?
Thank you
I tried to integration error log laravel to slack notification. But when i tested to send log it can't send massage to slack. I followed this tutorial https://panjeh.medium.com/send-laravel-6-log-to-slack-notification-573a6d95a14e. And I've tested on route too
Here is it the config.php
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single','slack'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'warning',
],
Here is it the route to test
Route::get('slack', function() {
Log::error('Test');
return 'Slack notif';
});
I've got the url too and have it put in .env LOG_SLACK_WEBHOOK_URL=
You can change default log channels to slack.So you have to set
LOG_CHANNEL=stack
Also you can specify channels. Instead of changing channels
Log::channel('slack')->inf("test");
or you can do
Log::stack(['daily', 'slack'])->info("test");
or you can specify channels inside daily array.So that no need to change anythink
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'slack'],
'ignore_exceptions' => false,
],
I have a Redis 6.x instance on AWS Elasticache. It is clustered, and has in-transit encryption. I also have a RBAC set up (User with a password in AWS). I am able to connect using the redis-cli and then authorize using AUTH <password> and it works great. (It uses Redis 6 ACL feature)
However when I add the password to my Laravel configuration I get the error:
Couldn't map cluster keyspace using any provided seed
If I remove the password from the User in Elasticache, Laravel connects fine and uses Redis perfectly.
Here is my configuration. The password is correct in my env file and because of clustering, is added both in default connection and in the options['parameters'] key.
'redis' => [
'client' => 'phpredis',
'cluster' => true,
'clusters' => [
'default' => [
[
'scheme' => 'tls',
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
'options' => [
'cluster' => 'redis',
],
],
'options' => [
'parameters' => [
'scheme' => 'tls',
'password' => env('REDIS_PASSWORD', null),
],
'ssl' => ['verify_peer' => false],
'context' => [],
],
],
I've seen this error before but it seems like it occurs whenever something bad happens, rather than giving me specifics. For example, if I remove the password, and restrict some of the access permissions like SET or READ/WRITE commands, then I also get the same error, and so it is very hard to decipher what the error is.
Are you using Laravel 5 or 6?
Our setup is similar to yours, but this solution only seems to work with Laravel 6, but when I use this same configuration, I get the same issue as you in Laravel 5.
'redis' => [
'client' => 'phpredis',
'cluster' => true,
'options' => [
'cluster' => 'redis',
'ssl' => ['verify_peer' => false],
'context' => [],
'password' => env('REDIS_PASSWORD', null),
'parameters' => [
'scheme' => env('REDIS_SCHEME', 'tls'),
],
],
'clusters' => [
'default' =>
[
[
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 0),
'persistent' => true,
],
],
'options' => [
'cluster' => 'redis',
]
],
],
Now to figure out how to make my Laravel 5 app work, (Or I'll just have to upgrade my Laravel Apps).
I am running my Laravel 7 application for testing purposes on a shared host.
My logging.php configuration looks like the following:
<?php
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
return [
'default' => env('LOG_CHANNEL', 'single'),
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'error',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'papertrail' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
],
'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
],
];
I only get the log file from the day before in my storage folder. However, I would like to get the logs that are created when the application runs, like a log stream.
Any suggestions how to do this?
I appreciate your replies!
so far, I am new to logs too. The two lines below can be added to any controller
use Log; #on top along with the other 'use' statements
this 2nd line would be inserted as needed:
Log::info('File: '. __FILE__. ' This would get logged on file: storage/laravel.log');
The result is appended onto laravel.log and would be similar to:
[2020-07-11 05:08:38] local.INFO: File: C:\<someFolders>\laravel\vendor\laravel\framework\src\Illuminate\Routing\Route.php This would get logged on file: storage/laravel.log
'hope it helps.
What does the 'queue' => 'default' setting do at config/queue.php?
It seems like it does not affect anything.
In config/queue.php my queue configuration is ga-fetcher-queue.
This is my config:
return [
'default' => 'redis',
'connections' => [
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'ga-fetcher-queue',
'retry_after' => 360,
],
],
'failed' => []
];
My redis config at config/database.php is this:
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
]