bee

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 4 Imported by: 0

README

bee

image

An asynchronous task execution framework based on the producer consumer model.

Features

supported middleware

  • redis
  • pulsar
  • rocketmq
  • rabbitmq

Install

go get -u github.com/bee-org/bee

Quick start

Redis example:

package main

import (
	"context"
	"fmt"
	"github.com/bee-org/bee"
	"github.com/bee-org/bee/broker/redis"
	"os"
)

func printHandler(c *bee.Context) error {
	var result int64
	err := c.Parse(&result)
	fmt.Println("printHandler", result, err)
	return nil
}

func main() {
	b, err := redis.NewBroker(redis.Config{
		URL:   os.Getenv("REDIS_URL"),
		Topic: "bee",
	})
	if err != nil {
		panic(err)
	}
	b.Register("print", printHandler)
	if err = b.Worker(); err != nil {
		panic(err)
	}

	b.Send(context.TODO(), "print", 1) // producer
	// output: printHandler 1 <nil>
}

RabbitMQ example:

package main

import (
	"context"
	"fmt"
	"github.com/bee-org/bee"
	"github.com/bee-org/bee/broker/amqp"
	"os"
)

func printHandler(c *bee.Context) error {
	var result int64
	err := c.Parse(&result)
	fmt.Println("printHandler", result, err)
	return nil
}

func main() {
	b, err := amqp.NewBroker(amqp.Config{
		URL:   os.Getenv("RABBIT_URL"),
		Queue: "bee",
	})
	if err != nil {
		panic(err)
	}
	b.Register("print", printHandler)
	if err = b.Worker(); err != nil {
		panic(err)
	}

	b.Send(context.TODO(), "print", 1) // producer
	// output: printHandler 1 <nil>
}

Message Protocol

bit:0-------8------16------24----------------n
    ┌───────┬───────┬───────┬────────────────┐
    │version│ retry │length │     name       │ header
    ├───────┴───────┴───────┴────────────────┤
    │                  body                  │
    └────────────────────────────────────────┘
  • version(8bit): Protocol Version number
  • retry(8bit): The number of times a message was redelivered
  • length(8bit): The length of the function name that follows
  • name(n-bit): The function name
  • body(n-bit): Data required for function execution

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

func NewCtx

func NewCtx(ctx context.Context, m message.Message) *Context

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) Message added in v0.1.1

func (c *Context) Message() message.Message

func (*Context) Name

func (c *Context) Name() string

func (*Context) Parse

func (c *Context) Parse(v interface{}) error

func (*Context) Req

func (c *Context) Req() interface{}

Req must be called after the Parse, Return the req recorded at parsing time.

func (*Context) Value

func (c *Context) Value(key interface{}) interface{}

type Handler

type Handler func(ctx *Context) error

type Option

type Option interface {
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL