Download the PHP package werk365/larakafka without Composer

On this page you can find all versions of the php package werk365/larakafka. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package larakafka

LaraKafka

Latest Version on Packagist Total Downloads StyleCI

Kafka client package for use in Laravel. Based on jobcloud/php-kafka-lib.

This package supports an extension to produce spatie activitylog activity automatically. Use werk365/larakafka-activity.

Without much configuration (simply making sure the config has the required broker information and credentials), you'll be able to enable the Spatie Activity Logging on a model, and this package will take care of also sending that information to a kafka topic corresponding with your application name.

Besides this basic logging feature, it also allows you to produce and consume anything you would want.

Producing can be easily done in-code, and you can start any number of consumers through:

Installation

Via Composer

Publish the config file using

Configuration

The publishes config file looks as follows, you can find an explanation below it.

Not all of the above configuration is needed for every usecase. If you just wish to use the activity logging feature, simply make sure to configure the client.configs.producer and client.broker.

Client

The producer and consumer configuration live here. This should be fairly straight forward. Do note that the default topic set for the producer will be the client.client_name value.

Functions

This is currently only used for the consumer, if you wish to consume a topic, the corresponding function will be called when a message is received. In this case while consuming the example topic, a static function \App\Services\KafkaService::ingest($key, $headers, $body) would be called. It is then up to your application to process that data.

Maps

Lastly, this is the configuration for the storeMessage() function. This function can be used to help easily process the data received from Kafka. This function expects an array of data and can map and store it to a database for you. Further information about this function in usage, but some configuration points:

model = The model that should be used to store the data

event_id = The key name of the unique id that belongs to the object

model_id = The key name of the unique id as it is called in the model

attributes = The attributes that should be stored for this model. Not all attributes configured here have to be present in the consumed message, as only updates attributes could be sent. The key represents the attribute key name as it is in the event, the value represents the key as it is called in the model.

Usage

Produce

Other available methods:

->setBroker("string") Sets broker other than defined in config

->setProducerConfig([]) Overrides config settings

->addProducerConfig("key", "value") Adds value to set config

->addHeaders([]) Merges added headers array in to set one

Octane Consumer

To run a consumer when using Laravel Octane, you can choose to either have it run through a Swoole worker or normally though a php process using the console command described in the next step. To use the Octane version, first make a new consumer using:

This will create a new consumer class in the App\Consumers namespace. For example: App\Consumers\TestConsumer when using test as the topic name.

In this consumer you will find a handleMessage() method which has everything you will need to start processing your messages. To make sure this consumer is started with your octane application, add the consumer to the listeners in the octane config file. I recommend adding it as a listener for the TickReceived event like so:

The consumer will only be started once and keep running, but putting it here will mean it will be started every octane-tick (every second), so the consumer can ensure it is still running. If the initial consumer has given no sign of live for 60 seconds, a new consumer will be started.

Console Consumer

To run a consumer, you can simply run

On reading a message, the function defined in your config will be called. If we have the function given in the example config, it could simply look like this:

If you wish to store the data received in the body, you can use the storeMessage method. This method takes in an array of attributes and an array of types. This means one array of attributes can be mapped and stored to different Models (types). In this example we'll only store one model, assuming the example config, and assuming the body has event_attributes which is an array containing attributes.

Change log

Please see the changelog for more information on what has changed recently.

Testing

WIP

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

license. Please see the license file for more information.


All versions of larakafka with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ~7|~8
jobcloud/php-kafka-lib Version ^1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package werk365/larakafka contains the following files

Loading the files please wait ....