定制 upingli/hofan 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

upingli/hofan

Composer 安装命令:

composer require upingli/hofan

包简介

Hofan lavaral components.

README 文档

README

Installation

You can install this package via composer using this command:

composer require upingli/hofan

The queue components in this package is based on vladimir-yuldashev/laravel-queue-rabbitmq. Because laravel-queue-rabbitmq serialize message in queue by using PHP serialize(), which can not be realized by the other language, it's unfriendly. This component provide a JSON serialized format for message to exchange message for the other non-PHP system.

Before use this component, you must config it.

Add connection to config/queue.php:

'default' => env('QUEUE_CONNECTION', 'sync'),
//Not required, if you want to use a second conenection to avoid use the default one, add the below line. Otherwise, will use the default.
'second'  => env('QUEUE_CONNECTION2', 'rabbitmq'),

'connections' => [
    // ...

    'rabbitmq' => [
    
       '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),
           ],
       ],
   
       /*
        * Set to "horizon" if you wish to use Laravel Horizon.
        */
       'worker' => env('RABBITMQ_WORKER', 'default'),
        
    ],

    // ...    
],

Example for create order using rabbitmq queue:

class TestController extends \Illuminate\Routing\Controller
{
    $order = new OrderTransit();
    OrderQueueCall::createOrder($order);
}

The result of createOrder() will be handled by cn\hofan\Queue\Jobs\OrderJsonJob. If you want to handle it yourself, there is a example.

Define your job:

class MyJob extends JsonJob
{
    protected function handle(string $command, $result)
    {
        if($command = "CREATE_ORDER_RESULT")
        {
            //Handle result for createOrder
        }

        return true;
    }
}

Then change the code in controller:

class TestController extends \Illuminate\Routing\Controller
{
    $order = new OrderTransit();
    OrderQueueCall::createOrder($order, MyJob::class);
}

统计信息

  • 总下载量: 62
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2020-11-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固