{"id":15187745,"url":"https://github.com/superbalist/laravel4-pubsub","last_synced_at":"2025-10-02T02:31:38.016Z","repository":{"id":10968345,"uuid":"67781155","full_name":"Superbalist/laravel4-pubsub","owner":"Superbalist","description":"A Pub-Sub abstraction for Laravel 4","archived":true,"fork":false,"pushed_at":"2022-07-25T07:52:34.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-01-16T20:09:51.797Z","etag":null,"topics":["laravel","laravel4","laravel4-package","laravel4-pubsub","php","php-pubsub","pubsub","superbalist"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Superbalist.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2016-09-09T08:28:40.000Z","updated_at":"2024-07-19T08:03:26.000Z","dependencies_parsed_at":"2022-07-24T20:32:21.847Z","dependency_job_id":null,"html_url":"https://github.com/Superbalist/laravel4-pubsub","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Flaravel4-pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Flaravel4-pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Flaravel4-pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Flaravel4-pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Superbalist","download_url":"https://codeload.github.com/Superbalist/laravel4-pubsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234929199,"owners_count":18908891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel4","laravel4-package","laravel4-pubsub","php","php-pubsub","pubsub","superbalist"],"created_at":"2024-09-27T18:43:24.359Z","updated_at":"2025-10-02T02:31:37.664Z","avatar_url":"https://github.com/Superbalist.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel4-pubsub\n\nA Pub-Sub abstraction for Laravel 4.\n\n[![Author](http://img.shields.io/badge/author-@superbalist-blue.svg?style=flat-square)](https://twitter.com/superbalist)\n[![Build Status](https://img.shields.io/travis/Superbalist/laravel4-pubsub/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/laravel4-pubsub)\n[![StyleCI](https://styleci.io/repos/67781155/shield?branch=master)](https://styleci.io/repos/67781155)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Packagist Version](https://img.shields.io/packagist/v/superbalist/laravel4-pubsub.svg?style=flat-square)](https://packagist.org/packages/superbalist/laravel4-pubsub)\n[![Total Downloads](https://img.shields.io/packagist/dt/superbalist/laravel4-pubsub.svg?style=flat-square)](https://packagist.org/packages/superbalist/laravel4-pubsub)\n\nThis package is a wrapper bridging [php-pubsub](https://github.com/Superbalist/php-pubsub) into Laravel 4.\n\nFor **Laravel 5** support, use the package https://github.com/Superbalist/laravel-pubsub\n\nThe following adapters are supported:\n* Local\n* /dev/null\n* Redis\n* Kafka (see separate installation instructions below)\n* Google Cloud\n* HTTP\n\n## Installation\n\n```bash\ncomposer require superbalist/laravel4-pubsub\n```\n\nThe package has a default configuration built-in.\n\nTo customize the configuration file, publish the package configuration using Artisan.\n```bash\nphp artisan config:publish superbalist/laravel4-pubsub\n```\n\nYou can then edit the generated config at `app/config/packages/superbalist/laravel4-pubsub/config.php`.\n\nRegister the service provider in app.php\n```php\n'providers' =\u003e [\n    // ...\n    'Superbalist\\Laravel4PubSub\\PubSubServiceProvider'\n]\n```\n\nRegister the facade in app.php\n```php\n'aliases' =\u003e [\n    // ...\n    'PubSub' =\u003e 'Superbalist\\Laravel4PubSub\\PubSubFacade',\n]\n```\n\n## Kafka Adapter Installation\n\nPlease note that whilst the package is bundled with support for the [php-pubsub-kafka](https://github.com/Superbalist/php-pubsub-kafka)\nadapter, the adapter is not included by default.\n\nThis is because the KafkaPubSubAdapter has an external dependency on the `librdkafka c library` and the `php-rdkafka`\nPECL extension.\n\nIf you plan on using this adapter, you will need to install these dependencies by following these [installation instructions](https://github.com/Superbalist/php-pubsub-kafka).\n\nYou can then include the adapter using:\n```bash\ncomposer require superbalist/php-pubsub-kafka\n```\n\n## Usage\n\n```php\n// get the pub-sub manager\n$pubsub = app('pubsub');\n\n// note: function calls on the manager are proxied through to the default connection\n// eg: you can do this on the manager OR a connection\n$pubsub-\u003epublish('channel_name', 'message');\n\n// get the default connection\n$pubsub = app('pubsub.connection');\n// or\n$pubsub = app(\\Superbalist\\PubSub\\PubSubAdapterInterface::class);\n\n// get a specific connection\n$pubsub = app('pubsub')-\u003econnection('redis');\n\n// publish a message\n// the message can be a string, array, bool, object - anything which can be json encoded\n$pubsub-\u003epublish('channel_name', 'this is where your message goes');\n$pubsub-\u003epublish('channel_name', ['key' =\u003e 'value']);\n$pubsub-\u003epublish('channel_name', true);\n\n// publish multiple messages\n$messages = [\n    'message 1',\n    'message 2',\n];\n$pubsub-\u003epublishBatch('channel_name', $messages);\n\n// subscribe to a channel\n$pubsub-\u003esubscribe('channel_name', function ($message) {\n    var_dump($message);\n});\n\n// all the above commands can also be done using the facade\nPubSub::connection('kafka')-\u003epublish('channel_name', 'Hello World!');\n\nPubSub::connection('kafka')-\u003esubscribe('channel_name', function ($message) {\n    var_dump($message);\n});\n```\n\n## Creating a Subscriber\n\nA lot of pub-sub adapters will contain blocking `subscribe()` calls, so these commands are best run as daemons running\nas a [supervisor](http://supervisord.org) process.\n\nThis is a sample subscriber written as an artisan command.\n```php\n\u003c?php\n\nnamespace App\\Commands;\n\nuse App;\nuse Illuminate\\Console\\Command;\n\nclass MyExampleSubscriber extends Command\n{\n    /**\n     * The name and signature of the subscriber command.\n     *\n     * @var string\n     */\n    protected $name = 'subscriber:name';\n\n    /**\n     * The subscriber description.\n     *\n     * @var string\n     */\n    protected $description = 'PubSub subscriber for ________';\n\n    /**\n     * Execute the console command.\n     */\n    public function fire()\n    {\n        $pubsub = App::make('pubsub');\n        $pubsub-\u003esubscribe('channel_name', function ($message) {\n\n        });\n    }\n}\n```\n\n### Kafka Subscribers ###\n\nFor subscribers which use the `php-pubsub-kafka` adapter, you'll likely want to change the `consumer_group_id` per\nsubscriber.\n\nTo do this, you need to use the `PubSubConnectionFactory` to create a new connection per subscriber.  This is because\nthe `consumer_group_id` cannot be changed once a connection is created.\n\nHere is an example of how you can do this:\n\n```php\n\u003c?php\n\nnamespace App\\Commands;\n\nuse App;\nuse Config;\nuse Illuminate\\Console\\Command;\n\nclass MyExampleKafkaSubscriber extends Command\n{\n    /**\n     * The name and signature of the subscriber command.\n     *\n     * @var string\n     */\n    protected $name = 'subscriber:name';\n\n    /**\n     * The subscriber description.\n     *\n     * @var string\n     */\n    protected $description = 'PubSub subscriber for ________';\n\n    /**\n     * Execute the console command.\n     */\n    public function fire()\n    {\n        $config = Config::get('laravel4-pubsub::connections.kafka');\n        $config['consumer_group_id'] = self::class;\n        $factory = App::make('pubsub.factory');\n        $pubsub = $factory-\u003emake('kafka', $config);\n        $pubsub-\u003esubscribe('channel_name', function ($message) {\n\n        });\n    }\n}\n```\n\n## Adding a Custom Driver\n\nPlease see the [php-pubsub](https://github.com/Superbalist/php-pubsub) documentation  **Writing an Adapter**.\n\nTo include your custom driver, you can call the `extend()` function.\n\n```php\n$manager = app('pubsub');\n$manager-\u003eextend('custom_connection_name', function ($config) {\n    // your callable must return an instance of the PubSubAdapterInterface\n    return new MyCustomPubSubDriver($config);\n});\n\n// get an instance of your custom connection\n$pubsub = $manager-\u003econnection('custom_connection_name');\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperbalist%2Flaravel4-pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperbalist%2Flaravel4-pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperbalist%2Flaravel4-pubsub/lists"}