Git Product home page Git Product logo

laravel-fanout's Introduction

laravel-fanout

Author: Konstantin Bokarius [email protected]

Fanout.io library for Laravel.

Credit

This project is based on the following pull request by Christopher Thomas: https://github.com/cwt137/laravel-framework/commit/b64b57ec0dfac975db9fadecac9f7a3757b7af30

Requirements

  • openssl
  • curl
  • pthreads (required for asynchronous publishing)
  • php >=7.0.0
  • laravel >= 5.5
  • fanout/fanout >=2.0.0 (retrieved automatically via Composer)

Installation

Using Composer:

composer require fanout/laravel-fanout

Manual: ensure that php-fanout has been included and require the following files in laravel-fanout:

require 'laravel-fanout/src/fanoutbroadcaster.php';
require 'laravel-fanout/src/fanoutbroadcastserviceprovider.php';

Asynchronous Publishing

In order to make asynchronous publish calls pthreads must be installed. If pthreads is not installed then only synchronous publish calls can be made. To install pthreads recompile PHP with the following flag: '--enable-maintainer-zts'

Also note that since a callback passed to the publish_async methods is going to be executed in a separate thread, that callback and the class it belongs to are subject to the rules and limitations imposed by the pthreads extension.

See more information about pthreads here: http://php.net/manual/en/book.pthreads.php

Usage

In your config/broadcasting.php file set the default driver to 'fanout' and add the connection configuration like so:

'default' => 'fanout',

'connections' => [
    ...
    'fanout' => [
        'driver' => 'fanout',
        'realm_id' => '<my-realm-id>',
        'realm_key' => '<my-realm-key>',
        'ssl' => true,
        'publish_async' => false
    ],
    ...
]

In your config/app.php file add the following provider to your service providers array:

'providers' => [
    ...
    LaravelFanout\FanoutBroadcastServiceProvider::class,
    ...
]

Add a custom broadcast event to your application like so:

namespace App\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class PublishToFanoutEvent implements ShouldBroadcast
{
    use SerializesModels;

    public $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function broadcastOn()
    {
        return ['<channel>'];
    }
}

Now to publish to Fanout.io in your application simply fire the event:

event(new App\Events\PublishToFanoutEvent('Test publish!!'));

laravel-fanout's People

Contributors

garethtdavies avatar jkarneges avatar seanmangar avatar tomhatzer avatar

Stargazers

marz avatar Kan avatar  avatar  avatar abdelwahed mohamed avatar Luiz Carlos avatar Matheus Lima avatar Cody avatar Collin Schneider avatar Tommi Finnilä avatar Phillipp Ohlandt avatar

Watchers

Jan Niehusmann avatar  avatar  avatar James Cloos avatar Katsuyuki Omuro avatar  avatar

laravel-fanout's Issues

Lumen 5.3 support?

Lumen 5.3's broadcaster class has an auth and a validAuthenticationResponse function that needs to be implemented.

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.