GithubHelp home page GithubHelp logo

rabbit's Introduction

Rabbit

rabbit-hero

Introduction

If you ever want a way to trigger your Laravel jobs from Golang to leverage the features that Laravel Horizon provides. Rabbit is the package for you.

Installation

Run the following command to install rabbit on your Go project:

go get github.com/ichtrojan/rabbit

Config

queue := rabbit.Config{
    AppName: "horizon",
    Conn:    client,
    Job:     "App\\Jobs\\SendEmail",
    Queue:   "default",
    Delay:   10,
}
Attribute Description
AppName Your APP_NAME as set in your laravel's app .env file
Conn Redis connection
Job The laravel job namespace
Queue The queue name, the default queue name is default
Delay Delay in seconds

Parameters

The parameters should mirror the construct on your laravel job. For example, if you have a job with a construct like this:

<?php
...
class ExampleJob {
    public $id;
    private $address;
    protected $message;

    public function __construct($id, $address, $message)
    {
        $this->id = $id;
        $this->address = $address;
        $this->message = $message;
    }
    ...
}

Your horizon parameter definition should look like this:

params := []rabbit.Param{
    {Type: "public", Name: "id", Value: "0000-000000-00000-00000"},
    {Type: "private", Name: "address", Value: "1 Apple Park Way, Cupertino, California, USA"},
    {Type: "protected", Name: "message", Value: "stay foolish, stay hungry"},
}

NOTE

  • Supported parameter types are public, private and protected.
  • Objects/Models cannot be passed as parameters and modifying your Job on laravel may be required.
  • Declaring an invalid parameter type would default to public.

Usage

Ensure you have Laravel Horizon installed and running on your laravel application, you can do that by running:

php artisan horizon

Alternatively, this would also work if you use the default queue worker that comes prepackaged with laravel.

php artisan queue:work redis

Here's a sample code with everything defined:

package main

import (
	"fmt"
	"github.com/go-redis/redis"
	"github.com/ichtrojan/rabbit"
)

func main() {
	client := redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%s", "127.0.0.1", "6379"),
		Password: "",
		DB:       0,
	})

	queue := rabbit.Config{
		AppName: "rabbit",
		Conn:    client,
		Job:     "App\\Jobs\\SendEmail",
		Queue:   "default",
		Delay:   10,
	}

	params := []rabbit.Param{
		{Type: "public", Name: "id", Value: "0000-000000-00000-00000"},
		{Type: "private", Name: "address", Value: "1 Apple Park Way, Cupertino, California, USA"},
		{Type: "protected", Name: "message", Value: "stay foolish, stay hungry"},
	}

	if err := queue.Dispatch(params...); err != nil {
		fmt.Println(err)
	}
}

Contributor(s)

rabbit's People

Contributors

ichtrojan avatar voenniy avatar

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.