Code Monkey home page Code Monkey logo

laravel-amqp's Introduction

bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages especially from RabbitMQ

Build Status Latest Stable Version License

Features

  • Advanced queue configuration
  • Add message to queues easily
  • Listen queues with useful options

Installation

Composer

Add the following to your require part within the composer.json:

"bschmitt/laravel-amqp": "2.*" (Laravel >= 5.5)
"bschmitt/laravel-amqp": "1.*" (Laravel < 5.5)
$ php composer update

or

$ php composer require bschmitt/laravel-amqp

Integration

Lumen

Create a config folder in the root directory of your Lumen application and copy the content from vendor/bschmitt/laravel-amqp/config/amqp.php to config/amqp.php.

Adjust the properties to your needs.

return [

    'use' => 'production',

    'properties' => [

        'production' => [
            'host'                => 'localhost',
            'port'                => 5672,
            'username'            => 'username',
            'password'            => 'password',
            'vhost'               => '/',
            'exchange'            => 'amq.topic',
            'exchange_type'       => 'topic',
            'consumer_tag'        => 'consumer',
            'ssl_options'         => [], // See https://secure.php.net/manual/en/context.ssl.php
            'connect_options'     => [], // See https://github.com/php-amqplib/php-amqplib/blob/master/PhpAmqpLib/Connection/AMQPSSLConnection.php
            'queue_properties'    => ['x-ha-policy' => ['S', 'all']],
            'exchange_properties' => [],
            'timeout'             => 0
        ],

    ],

];

Register the Lumen Service Provider in bootstrap/app.php:

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
*/

//...

$app->configure('amqp');
$app->register(Bschmitt\Amqp\LumenServiceProvider::class);

//...

Add Facade Support for Lumen 5.2+

//...
$app->withFacades(true, [
    'Bschmitt\Amqp\Facades\Amqp' => 'Amqp',
]);
//...

Laravel

Open config/app.php and add the service provider and alias:

'Bschmitt\Amqp\AmqpServiceProvider',
'Amqp' => 'Bschmitt\Amqp\Facades\Amqp',

Publishing a message

Push message with routing key

    Amqp::publish('routing-key', 'message');

Push message with routing key and create queue

    Amqp::publish('routing-key', 'message' , ['queue' => 'queue-name']);

Push message with routing key and overwrite properties

    Amqp::publish('routing-key', 'message' , ['exchange' => 'amq.direct']);

Consuming messages

Consume messages, acknowledge and stop when no message is left

Amqp::consume('queue-name', function ($message, $resolver) {
    		
   var_dump($message->body);

   $resolver->acknowledge($message);

   $resolver->stopWhenProcessed();
        
});

Consume messages forever

Amqp::consume('queue-name', function ($message, $resolver) {
    		
   var_dump($message->body);

   $resolver->acknowledge($message);
        
});

Consume messages, with custom settings

Amqp::consume('queue-name', function ($message, $resolver) {
    		
   var_dump($message->body);

   $resolver->acknowledge($message);
      
}, [
	'timeout' => 2,
	'vhost'   => 'vhost3'
]);

Fanout example

Publishing a message

\Amqp::publish('', 'message' , [
    'exchange_type' => 'fanout',
    'exchange' => 'amq.fanout',
]);

Consuming messages

\Amqp::consume('', function ($message, $resolver) {
    var_dump($message->body);
    $resolver->acknowledge($message);
}, [
    'routing' => '',
    'exchange' => 'amq.fanout',
    'exchange_type' => 'fanout',
    'queue_force_declare' => true,
    'queue_exclusive' => true,
    'persistent' => true // required if you want to listen forever
]);

Credits

License

This package is open-sourced software licensed under the MIT license

laravel-amqp's People

Contributors

aidask avatar alupuleasa avatar bschmitt avatar cellard avatar dennisgon avatar du-disk avatar emil-nasso avatar hertzigger avatar joskfg avatar junaidnasir avatar jwkblades avatar lukebakken avatar mattbearson avatar mirkojotic avatar ni-bschmitt avatar pe46dro avatar petekelly avatar rmundel avatar sergeyklay avatar slowpokefarm avatar smartyaunt avatar spacek33z avatar stevenklar avatar xaviapa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-amqp's Issues

Send direct message into queue, when you defined exchange_type=topic

Hello guys,

I got a problem, but maybe you know the solution.
If I set up exhange_type = topic in amqp.php(settings), can I send direct message into particular queue, not to topic.
I tried a things like that:

$amqpObj->publish('', json_encode($data), [
            'queue' => $queueName
        ]);

but it binds my queue to the default topic and send message into default topic. So, if I have for example 10 REST api with different queues, all of them will be binded to one topic and all will get messages, which is incorrect.
So, do you have a way - how I can use 2 ways: one function sent message into topic and another one send just directly into one queue(and do not bind queue to the default topic)?
Thanks

No version tagged

The readme says that you can add "bschmitt/laravel-amqp": "1.*" to your composer file, but this isn't true because no version is tagged. Could you tag a version (maybe 0.1.0)?

Thanks for this awesome package, we're going to use it a lot.

Unable to Connect

I'm Using Laravel 5.2. and where should I add my login credentials of RabbitMQ?.

stream_socket_client(): unable to connect to tcp://: (Failed to parse address ":")

How to consume the message in Laravel

Hi,

I am using this package to publish and consume the message using RabbitMQ in a Microservices based application. I am publishing the message in service and trying to consume the same in another service.

The documentation is pretty clear on the code to consume the published message in the queue. However, in the traditional Laravel queue process, we would describe the process to be performed inside the handle() method. And call the php artisan queue:work command to execute the queue.

But here in the documentation, the code is clear to consume the message but How to consume the message and execute the same with an artisan command is confusing.

where would I write the code below code in Laravel application and listen to it in production server:

Amqp::consume('queue-name', function ($message, $resolver) {
    		
   var_dump($message->body);

   $resolver->acknowledge($message);
        
});

Unable to use default exchange

Setting exchange to '' gives the error that the exchange parameter isn't provided in the config.
$channel->basic_publish() in php-amqplib accepts '' as the default exchange though, sending to a queue with the same name as the routing key.
Another issue ( after commenting the empty($this->getProperty('exchange')) check ), is that you always declare an exchange. That is denied for the default exchange. Commenting out the exchange-declare block as well makes me successfully deliver a message to my queue through the default exchange.

Disable exchange and queue declare in setup method

Hello!

It would be great if exchange and queue declaration could be disabled in setup method, cause if you declared a queue for example with dead letter exchange, you have to define this property in consume method, otherwise rabbit will throw an error because your package is try to define a queue with the same name and another properties.

Another problem is you dont merge the queue_properties key with defaults, so i have to add the defaults manually to the properties to every time in my code.

Anyway i think it's not okay that the code always try to declare queues and exchanges cause it's unnecessary communication every time with the server. It would be great to pass a property to declare these things in setup or not.

Thanks!

Need some suggestion on AMQP Consume

I am looking to bind a queue with exchange and routing key while consuming. Do anyone help me out to achieve the above using this (bschmitt/laravel-amqp) library?

I have to do something like below:
$binding_key = 'black';
$channel->queue_bind($queue_name, $exchange_name, $binding_key);

Will the below code works:

$connection = new AMQP();
$channel = $connection->channel();
$channel->queue_bind($queue_name, $exchange_name, $binding_key);

Will be great if anyone suggest me with the working code.

Doesn't allow to use an existing exchange with just write permissions.

The way the code is written, it always tries to declare an exchange. And that requires the configure permissions on the exchange resource from the user part. If the user has just write permissions and just wants to publish to that exchange, it raises an exception of access refused. Something that is not expected.

Php amqplib basic_publish allows users to publish messages to given exchange with just write permissions.

Howto restart after fresh deployed code ?

Hi,
Thanks for Ur nice work :-)

Laravel Queues have a queue:restart command, to use after deployed fresh code (usually in composer 'post-install-cmd' event).
How to do with laravel-amqp when listening forever ?
Is there a way to create command like laravel-amqp:restart ?

Thanks & cheers

Automatic Subscribe Technique

I am looking to subscribe automatically and display it on the front end once I received.

Is there a way to do such? Can you please guide me to achieve?

routing and listen

Consumer right now does not make to much sense for my use case.
When im publishing new things i publish it to routing key.

i would like some API like this
Amqp::listen('routing.key,other.key', callback)

this would generate new queue behind the scenes and consume those routing keys.
with current setup i have to create new queue for every routing key and bind it to that routing key.

Also i needed the RPC so im implementing it.

i have something like this.
$response = Amqp::rpc('routing.key');

and for a rpc listener the consumer/listener could be the same as in publish with a difference where in callback we would call something like $resolver->replay(...

right now i have forked and playing with it to suit my needs but i would like if we can implement something like this here so i dont have to keep a local copy of this i my project.

Error after reading from consumer

I'm just using this plug-in as a consumer in an Artisan Command of a RabbitMQ queue that is fed elswhere.

Everything reads correctly. At the end I get the following error


PHP Fatal error:  Uncaught Error: Call to a member function send_channel_method_frame() on null in /opt/worldeducation/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php:116
Stack trace:
#0 /opt/worldeducation/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(97): PhpAmqpLib\Channel\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\Wire\AMQPWriter))
#1 /opt/worldeducation/vendor/bschmitt/laravel-amqp/src/Request.php(145): PhpAmqpLib\Channel\AMQPChannel->close()
#2 [internal function]: Bschmitt\Amqp\Request::shutdown(Object(PhpAmqpLib\Channel\AMQPChannel), Object(PhpAmqpLib\Connection\AMQPSSLConnection))
#3 {main}
  thrown in /opt/worldeducation/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php on line 116

My code

public function handle()
    {

        Amqp::consume('brain_etl', function ($message, $resolver) {

            try {

                $zohoETL = new ZohoETL();
                $zohoETL->payload = $message->body;
                $zohoETL->save();

                $resolver->acknowledge($message);

                $resolver->stopWhenProcessed();
            } catch (Exception $exception) {
                $this->info('Done processing');
            }

        });

    }

I put in the try/catch to try to eliminate the console display, but that didn't change anything.

Any ideas of how to fix this would be appreciated

how to connect to a partner's message broker server without adding exchange or empty exchange.

I am using the "bschmitt / laravel-amqp" 2.0 library and I need to connect to the partner's message broker server. It seems they don't accept any exchange parameters in the connection. But when I modified the "exchange" and "exchange_type" fields in the "config / amqp.php" file, I got the error "Please check your settings, exchange is not defined".
The following image is my fault and configuration section.
My English is not very good, if there are grammatical errors please ignore. Thanks
error
CONFIG_FILE

Publish config file via service provider

Laravel allows to publish the config file like this. It's cumbersome to copy the file from the repo.

I think, this should be added because publishing config files is de-facto standard for laravel packages.

Support for channel->basic_qos

Would be useful to add basic_qos call before basic_consume
especially for prefetch_count option
http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos
https://github.com/php-amqplib/php-amqplib/blob/master/demo/basic_qos.php

Its a must if you want to run a multiple consumer scenario and control the batch size distributed to each consumer (right now the default is 1000 messages).

Currently the simple workaround is to extend \Bschmitt\Amqp\Consumer and add basic_qos call before parent::consume(), after that you just overwrite the bind for \Bschmitt\Amqp\Consumer with your own extended class.
A config option would be more elegant

require conflict in Lumen 5.6

Hi,I met some problem when i run "composer require bschmitt/laravel-amqp" in Lumen 5.6, such as following text:

`Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for tightenco/collect (locked at v5.6.24) -> satisfiable by tightenco/collect[v5.6.24].
- bschmitt/laravel-amqp 2.0.0 requires illuminate/support v5.5.28 -> satisfiable by illuminate/support[v5.5.28].
- bschmitt/laravel-amqp 2.0.1 requires illuminate/support v5.5.28 -> satisfiable by illuminate/support[v5.5.28].
- Conclusion: don't install illuminate/support v5.5.28
- Installation request for bschmitt/laravel-amqp ^2.0 -> satisfiable by bschmitt/laravel-amqp[2.0.0, 2.0.1].

Installation failed, reverting ./composer.json to its original content.`

then i found your project require "illuminate/support": "v5.5.28", and Lumen 5.6 require "illuminate/support": "5.6.*",so any suggestion? thanks!

Write integration tests

The goal is to have integration tests which can be executed with upcoming Laravel and Lumen versions. In best case integrated into travis-ci

How do I use the topic pattern

hello,I had a problem using this package

My question is that I want to use rabbitmq through topic mode. I use the mode of matching routes, but it has no effect. May I ask how I should use it or do you have any examples for reference?

Amqp::publish('fruit.red', 'message2' , [ 'exchange_type' => 'topic', 'exchange' => 'test.topick', ]);

Amqp::consume('red.queue', function ($message, $resolver) { var_dump($message->body); $resolver->acknowledge($message); }, [ 'routing' => '*.red', 'exchange' => 'test.topic', 'exchange_type' => 'topic', 'persistent' => true // required if you want to listen forever ]);

closing connection after publish

I believe connections are never closed after publishing, looks like the same is happening when consuming to.

There is a static function shutdown() but that is never called...

Use multiple RabbitMQ instances

Hi,

First of all, thanks for this amazing library. Second, I would like to know how to configure 2 separate instances?

I kinda know how to do it in the config file but not while using it, you know like when you need to use multiple db instances.

$users = DB::connection('foo')->select(...);

Thanks,

Reject method

Hi Björn,

I've added a reject method to your consumer class to requeue messages if execution/consumption fails. Not sure of you want it in your lib or not.

    /**
     * Rejects a message and requeues it if wanted.
     *
     * @param Message $message
     * @param bool $requeue
     */
    public function reject($message, $requeue)
    {
        $message->delivery_info['channel']->basic_reject($message->delivery_info['delivery_tag'], $requeue);
    }

Cheers,
Rob

Whether to support header pattern

hi

I did not find the usage supporting header mode in the package, may I ask whether the use of header mode is supported and how should I call the example

and

I see someone submitting an RPC call, when can it be used

Looking for maintainer

As my time is limited recently and I guess this package is quite helpful for others, I want to ask if there is someone which can help me or take over the ownership?

how would you consume raw rabbitmq messages indefinitely?

I’m using this project for producing rabbitmq messages to the rest of the infrastructure it interacts with without any issue.

My question is: how would you consume raw rabbitmq messages indefinitely within Laravel without blocking other normal HTTP requests?

I noticed that the basic description does mention “Consume messages forever” and that is exactly what I'm aiming for, however if I were to do so wouldn't that block all http requests?

Would I use the supervisor for this and if so, how do I ensure that supervisor will run my consumer and not Laravel’s queue? I need for other services (that use a custom formatted message – ie, not Laravel’s message format) to send messages to Laravel.

Any help or pointers you may provide is much appreciated.

AMQPTables Support

hai i used lumen 5.8.8 to send message headers properties. and it got error

[2019-06-20 09:07:57] local.ERROR: PhpAmqpLib\Exception\AMQPOutOfRangeException: AMQP-rabbit doesn't define data of type [] in C:\laragon\www\kompas-id-apiwcm\vendor\php-amqplib\php-amqplib\PhpAmqpLib\Wire\AMQPAbstractCollection.php:420
Stack trace:
#0 C:\laragon\www\kompas-id-apiwcm\vendor\php-amqplib\php-amqplib\PhpAmqpLib\Wire\AMQPWriter.php(425): PhpAmqpLib\Wire\AMQPAbstractCollection::getDataTypeForSymbol(NULL)
#1 C:\laragon\www\kompas-id-apiwcm\vendor\php-amqplib\php-amqplib\PhpAmqpLib\Wire\AMQPWriter.php(443): PhpAmqpLib\Wire\AMQPWriter->write_table(Array)
#2 C:\laragon\www\kompas-id-apiwcm\vendor\php-amqplib\php-amqplib\PhpAmqpLib\Wire\GenericContent.php(199): PhpAmqpLib\Wire\AMQPWriter->write_table_object(Array)
#3 C:\laragon\www\kompas-id-apiwcm\vendor\php-amqplib\php-amqplib\PhpAmqpLib\Channel\AMQPChannel.php(1123): PhpAmqpLib\Wire\GenericContent->serialize_properties()
#4 C:\laragon\www\kompas-id-apiwcm\vendor\bschmitt\laravel-amqp\src\Publisher.php(18): PhpAmqpLib\Channel\AMQPChannel->basic_publish(Object(Bschmitt\Amqp\Message), 'amq.headers', 'routing-key')
#5 C:\laragon\www\kompas-id-apiwcm\vendor\bschmitt\laravel-amqp\src\Amqp.php(33): Bschmitt\Amqp\Publisher->publish('routing-key', Object(Bschmitt\Amqp\Message))
#6 C:\laragon\www\kompas-id-apiwcm\vendor\illuminate\support\Facades\Facade.php(237): Bschmitt\Amqp\Amqp->publish('routing-key', Object(Bschmitt\Amqp\Message), Array)
#7 C:\laragon\www\kompas-id-apiwcm\app\Http\Controllers\V1\MembershipController.php(64): Illuminate\Support\Facades\Facade::__callStatic('publish', Array)
#8 [internal function]: App\Http\Controllers\V1\MembershipController->create(Object(Laravel\Lumen\Http\Request))
#9 C:\laragon\www\kompas-id-apiwcm\vendor\illuminate\container\BoundMethod.php(32): call_user_func_array(Array, Array)
#10 C:\laragon\www\kompas-id-apiwcm\vendor\illuminate\container\BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#11 C:\laragon\www\kompas-id-apiwcm\vendor\illuminate\container\BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#12 C:\laragon\www\kompas-id-apiwcm\vendor\illuminate\container\Container.php(576): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#13 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(376): Illuminate\Container\Container->call(Array, Array)
#14 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(342): Laravel\Lumen\Application->callControllerCallable(Array, Array)
#15 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(316): Laravel\Lumen\Application->callLumenController(Object(App\Http\Controllers\V1\MembershipController), 'create', Array)
#16 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(278): Laravel\Lumen\Application->callControllerAction(Array)
#17 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(263): Laravel\Lumen\Application->callActionOnArrayBasedRoute(Array)
#18 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(165): Laravel\Lumen\Application->handleFoundRoute(Array)
#19 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(416): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(Object(Laravel\Lumen\Http\Request))
#20 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(171): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#21 C:\laragon\www\kompas-id-apiwcm\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(108): Laravel\Lumen\Application->dispatch(NULL)
#22 C:\laragon\www\kompas-id-apiwcm\public\index.php(28): Laravel\Lumen\Application->run()
#23 {main} {"exception":"[object] (PhpAmqpLib\\Exception\\AMQPOutOfRangeException(code: 0): AMQP-rabbit doesn't define data of type [] at C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\php-amqplib\\php-amqplib\\PhpAmqpLib\\Wire\\AMQPAbstractCollection.php:420)
[stacktrace]
#0 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\php-amqplib\\php-amqplib\\PhpAmqpLib\\Wire\\AMQPWriter.php(425): PhpAmqpLib\\Wire\\AMQPAbstractCollection::getDataTypeForSymbol(NULL)
#1 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\php-amqplib\\php-amqplib\\PhpAmqpLib\\Wire\\AMQPWriter.php(443): PhpAmqpLib\\Wire\\AMQPWriter->write_table(Array)
#2 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\php-amqplib\\php-amqplib\\PhpAmqpLib\\Wire\\GenericContent.php(199): PhpAmqpLib\\Wire\\AMQPWriter->write_table_object(Array)
#3 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\php-amqplib\\php-amqplib\\PhpAmqpLib\\Channel\\AMQPChannel.php(1123): PhpAmqpLib\\Wire\\GenericContent->serialize_properties()
#4 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\bschmitt\\laravel-amqp\\src\\Publisher.php(18): PhpAmqpLib\\Channel\\AMQPChannel->basic_publish(Object(Bschmitt\\Amqp\\Message), 'amq.headers', 'routing-key')
#5 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\bschmitt\\laravel-amqp\\src\\Amqp.php(33): Bschmitt\\Amqp\\Publisher->publish('routing-key', Object(Bschmitt\\Amqp\\Message))
#6 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\illuminate\\support\\Facades\\Facade.php(237): Bschmitt\\Amqp\\Amqp->publish('routing-key', Object(Bschmitt\\Amqp\\Message), Array)
#7 C:\\laragon\\www\\kompas-id-apiwcm\\app\\Http\\Controllers\\V1\\MembershipController.php(64): Illuminate\\Support\\Facades\\Facade::__callStatic('publish', Array)
#8 [internal function]: App\\Http\\Controllers\\V1\\MembershipController->create(Object(Laravel\\Lumen\\Http\\Request))
#9 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\illuminate\\container\\BoundMethod.php(32): call_user_func_array(Array, Array)
#10 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\illuminate\\container\\BoundMethod.php(90): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#11 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\illuminate\\container\\BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Laravel\\Lumen\\Application), Array, Object(Closure))
#12 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\illuminate\\container\\Container.php(576): Illuminate\\Container\\BoundMethod::call(Object(Laravel\\Lumen\\Application), Array, Array, NULL)
#13 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(376): Illuminate\\Container\\Container->call(Array, Array)
#14 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(342): Laravel\\Lumen\\Application->callControllerCallable(Array, Array)
#15 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(316): Laravel\\Lumen\\Application->callLumenController(Object(App\\Http\\Controllers\\V1\\MembershipController), 'create', Array)
#16 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(278): Laravel\\Lumen\\Application->callControllerAction(Array)
#17 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(263): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute(Array)
#18 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(165): Laravel\\Lumen\\Application->handleFoundRoute(Array)
#19 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(416): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}(Object(Laravel\\Lumen\\Http\\Request))
#20 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(171): Laravel\\Lumen\\Application->sendThroughPipeline(Array, Object(Closure))
#21 C:\\laragon\\www\\kompas-id-apiwcm\\vendor\\laravel\\lumen-framework\\src\\Concerns\\RoutesRequests.php(108): Laravel\\Lumen\\Application->dispatch(NULL)
#22 C:\\laragon\\www\\kompas-id-apiwcm\\public\\index.php(28): Laravel\\Lumen\\Application->run()
#23 {main}
"} 

my code is like this

$properties = [
                        'application_headers' => [
                            'source'=>'google_play'
                        ],
                        'content_type' => 'application/json',
                        'delivery_mode' => 2,
                        'priority' => 1

                    ];
                    $message = Amqp::message('messagesss',$properties);
                    Amqp::publish('routing-key', $message , ['exchange' => 'amq.headers']);

i see that the error because the application_headers cannot accept array so i used the AMQPTables in PhpAmqpLib\Wire\AMQPTable
like this

 $header = new AMQPTable();
                    $header->set('source','google_play');
                    $properties = [
                        'application_headers' => $header,
                        'content_type' => 'application/json',
                        'delivery_mode' => 2,
                        'priority' => 1

                    ];
                    $message = Amqp::message('messagesss',$properties);
                    Amqp::publish('routing-key', $message , ['exchange' => 'amq.headers']);

is there any support of AMQPTables in the wrapper? if not i will try to do pull request

Latest updates in php-amqplib/php-amqplib cause high CPU usage when using consume

Hey guys,

Due to the latest updates in the php-amqplib/php-amqplib (I describe them in more details here) the current way consume method is implemented causes an infinite loop in case blocking is set to false(which it is by default).
https://github.com/bschmitt/laravel-amqp/blob/master/src/Consumer.php#L73

This is due to the fact php-amqplib/php-amqplib disables timeouts for a non-blocking wait() (https://github.com/php-amqplib/php-amqplib/pull/642/files#diff-195c265ed9a66166715118df34df6ea3R339) and stops execution instead, leading to another wait cal, and so on, and so on.

You may probably want to reflect this in the documentation for consume to set that blocking => true in config, otherwise it may consume lots of CPU since php-amqplib 2.9.

array_key_exists() expects parameter 2 to be array, null given in Context.php line 76

Hello,

Function getProperty() from laravel-amqp/src/Context.php on line 63 returns null when array_key_exists returns false . I suggest to modify:

return array_key_exists($key, $this->properties) ? $this->properties[$key] : null;
to
return array_key_exists($key, $this->properties) ? $this->properties[$key] : [];

to avoid

array_key_exists() expects parameter 2 to be array, null given in Context.php line 76

Retry connection on fail

When running a persistent consumer, it sometimes happen that the AMQP server goes down or reboots.
Is there any way we can catch this event/exception and handle it ?

[ErrorException]                                                           
  fwrite(): send of 12 bytes failed with errno=104 Connection reset by peer  
                                                                             

PHP Fatal error:  Uncaught ErrorException: fwrite(): send of 19 bytes failed with errno=32 Broken pipe in .../php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:281
Stack trace:
#0 [internal function]: PhpAmqpLib\Wire\IO\StreamIO->error_handler(8, 'fwrite(): send ...', '/path/...', 281, Array)
#1 /vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php(281): fwrite(Resource id #285, '\x01\x00\x01\...', 8192)
#2 /vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(327): PhpAmqpLib\Wire\IO\StreamIO->write('\x01\x00\x01\...')
#3 /vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(448): PhpAmqpLib\Connection\AbstractConnection->write('\x01\x00\x01\...')
#4 /vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 281

Error in Consuming Queue using 2.0.6

Hi,
After we update to 2.0.6 the consumer returns an error.

ErrorException : mb_strlen() expects parameter 1 to be string, array given

at /var/www/html/gameservice/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPWriter.php:346
342| * @throws \PhpAmqpLib\Exception\AMQPInvalidArgumentException
343| */
344| public function write_shortstr($s)
345| {

346| $len = mb_strlen($s, 'ASCII');
347| if ($len > 255) {
348| throw new AMQPInvalidArgumentException('String too long');
349| }
350|

Exception trace:

1 mb_strlen([], "ASCII")
/var/www/html/gameservice/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/AMQPWriter.php:346

2 PhpAmqpLib\Wire\AMQPWriter::write_shortstr([])
/var/www/html/gameservice/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Helper/Protocol/Protocol091.php:438
image_2019_05_20T05_05_35_820Z

This only happened when we update to 2.0.6, but once we rollback to 2.0.3 there's no problem.

Cant get shrading to work

I am having issue using sharding. I want to achieve having one queue that has 6 consumers but with sharding to achieve that each consumer is on one CPU.

After enabling
rabbitmq-plugins enable rabbitmq_sharding

and setting up config

'exchange'              => 'shard.videos',
'exchange_type'         => 'x-modulus-hash',

making policy
rabbitmqctl set_policy videos-shard "^shard.videos$" "{""shards-per-node"": 1,""routing-key"": ""fc_analyze""}"

with
\Amqp::publish('fc_analyze', 'this is message');

I get it to wright queue but can not get consumer in that queue using this code

\Amqp::consume('videos', function ($message, $resolver) {
         var_dump($message->body);
         sleep(20);
         $resolver->acknowledge($message);
      }, [
      	'message_limit' => 1,
        'exchange' => 'shard.videos',
        'exchange_type' => 'x-modulus-hash',
        'routing_key' => 'fc-analyze',
     ]
);

Please help and advice.
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.