inventa

package module
v0.0.0-...-3911d0f Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: Apache-2.0 Imports: 8 Imported by: 8

README

Inventa for Go

LinkedIn Twitter HitCount License

A Go library for microservice registry and executing RPC (Remote Procedure Call) over Redis.

WHY THIS PROJECT?

Service discovery, registry, and execution of remote procedures are some of the necessary tools in distributed applications. You must track which services (also how many replica instances of them) are alive. Also, your services should communicate between each other (choreography) or via an orchestrator service on top of them.

You can do API/function calls remotely by serving REST APIs, gRPC endpoints, etc... But these choices came with some drawbacks or advantages, you have lots of different architectural options on this topic.

Inventa offers you a lightweight solution for these requirements; if you already have Redis in your project's toolbox, and if all of your services have access to this Redis instance.

Also, Inventa doesn't abstract/hide its Redis client object, you can use its Redis Client object freely which is already connected to the server.

USAGE SCENARIO

  • You have an application that consists of multiple services, developed with different languages (currently Go and Python are supported),
  • These services exist for different jobs, also they may be replicated into more than one instances, may be run in either different containers or machines,
  • There is one registrar/orchestrator service which other services will register themselves and send their heartbeats to it,
  • The orchestrator knows which service types and instances are alive now, the orchestrator should select one of the instances of a specific service, then call a function/procedure of the service, and get a response remotely.
  • All of your services will use Inventa, the one orchestrator service will instantiate it in Orchestrator Inventa role, other services will instantiate it in Service Inventa role.
  • Both Service roles and the Orchestrator role can call functions that are provided by other services if they know target service's identifier.

INSTALLATION

go get github.com/adalkiran/go-inventa

EXAMPLE PROJECT

You can find example projects made using Inventa at https://github.com/adalkiran/inventa-examples.

OTHER IMPLEMENTATIONS

You can find Python implementation of Inventa on Inventa for Python (py-inventa).

LICENSE

Inventa for Go is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Inventa

type Inventa struct {
	sync.Mutex

	Ctx                    context.Context
	Client                 *redis.Client
	SelfDescriptor         ServiceDescriptor
	InventaRole            InventaRole
	RPCCommandFnRegistry   map[string]RPCCommandFn
	OrchestratorDescriptor ServiceDescriptor
	IsOrchestratorActive   bool
	IsRegistered           bool

	OnServiceRegistering   func(serviceDescriptor ServiceDescriptor) error
	OnServiceUnregistering func(serviceDescriptor ServiceDescriptor, isZombie bool) error
	// contains filtered or unexported fields
}

func NewInventa

func NewInventa(host string, port int, password string, serviceType string, serviceId string, inventaRole InventaRole, rpcCommandFnRegistry map[string]RPCCommandFn) *Inventa

func (*Inventa) CallSync

func (r *Inventa) CallSync(serviceChannel string, method string, args []string, timeout time.Duration) ([]string, error)

func (*Inventa) DiscoverServices

func (r *Inventa) DiscoverServices()

func (*Inventa) GetAllActiveServices

func (r *Inventa) GetAllActiveServices() ([]ServiceDescriptor, error)

func (*Inventa) IsServiceActive

func (r *Inventa) IsServiceActive(serviceFullId string) bool

func (*Inventa) Start

func (r *Inventa) Start() (context.CancelFunc, error)

func (*Inventa) TryRegisterToOrchestrator

func (r *Inventa) TryRegisterToOrchestrator(orchestratorFullId string, tryCount int, timeout time.Duration) error

type InventaRole

type InventaRole byte
const (
	InventaRoleOrchestrator InventaRole = 1
	InventaRoleService      InventaRole = 2
)

type RPCCallRequest

type RPCCallRequest struct {
	CallId      string
	FromService ServiceDescriptor
	Method      string
	Args        []string
}

func (*RPCCallRequest) Decode

func (r *RPCCallRequest) Decode(raw string) error

func (*RPCCallRequest) Encode

func (r *RPCCallRequest) Encode() string

func (*RPCCallRequest) ErrorResponse

func (r *RPCCallRequest) ErrorResponse(err error) []string

type RPCCallResponse

type RPCCallResponse struct {
	CallId      string
	FromService ServiceDescriptor
	Data        []string
}

func (*RPCCallResponse) Decode

func (r *RPCCallResponse) Decode(raw string) error

func (*RPCCallResponse) Encode

func (r *RPCCallResponse) Encode() string

type RPCCommandFn

type RPCCommandFn func(req *RPCCallRequest) []string

type ServiceConsumer

type ServiceConsumer struct {
	SelfDescriptor ServiceDescriptor
	Inventa        *Inventa
}

func (ServiceConsumer) IsActive

func (s ServiceConsumer) IsActive() bool

type ServiceDescriptor

type ServiceDescriptor struct {
	ServiceType string
	ServiceId   string
}

func ParseServiceFullId

func ParseServiceFullId(serviceFullId string) (ServiceDescriptor, error)

func (*ServiceDescriptor) Decode

func (d *ServiceDescriptor) Decode(serviceFullId string) error

func (*ServiceDescriptor) Encode

func (d *ServiceDescriptor) Encode() string

func (*ServiceDescriptor) GetPubSubChannelName

func (d *ServiceDescriptor) GetPubSubChannelName() string

Jump to

Keyboard shortcuts

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