application

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Application is a collection of microservices that run in a single process and share the same lifecycle

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

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

Application is a collection of microservices that run in a single process and share the same lifecycle.

func New

func New() *Application

New creates a new application. An application is a collection of microservices that run in a single process and share the same lifecycle.

func NewTesting

func NewTesting() *Application

NewTesting creates a new application for running in a unit test environment. An application is a collection of microservices that run in a single process and share the same lifecycle. A random plane of communication is used to isolate the testing app from other apps. Tickers of microservices do not run in the TESTING deployment environment.

func (*Application) Add

func (app *Application) Add(services ...service.Service)

Add adds a collection of microservices to be managed by the app. Added microservices are not started up immediately. An explicit call to [Startup] is required. Microservices that are included together are started in parallel together. Otherwise, microservices are started sequentially in order of inclusion.

In the following example, A is started first, then B1 and B2 in parallel, and finally C1 and C2 in parallel.

app := application.New()
app.Add(a)
app.Add(b1, b2)
app.Add(c1, c2)
app.Startup()

func (*Application) AddAndStartup

func (app *Application) AddAndStartup(services ...service.Service) (err error)

AddAndStartup adds a collection of microservices to the app, and starts them up immediately.

func (*Application) Init

func (app *Application) Init(initializer func(svc service.Service))

Init sets up a method to call on each of the included microservices at the time they are included or joined. It is a convenience method to allow applying a generic operation en masse, for example, setting a shared configuration value during testing.

The is only one initializer. Consecutive calls overwrite the previous value. Pass nil to clear the initializer.

func (*Application) Interrupt

func (app *Application) Interrupt()

Interrupt the app.

func (*Application) Remove

func (app *Application) Remove(services ...service.Service)

Remove removes the microservices from under management of the app. Removed microservices are not shut down automatically and remain running on the same plane of communications.

func (*Application) Run

func (app *Application) Run() error

Run starts up all microservices included in this app, waits for interrupt, then shuts them down.

func (*Application) Shutdown

func (app *Application) Shutdown() error

Shutdown shuts down all started microservices included in this app in the reverse order of their starting up. If an error is returned, there is no guarantee as to the state of the microservices: some microservices may have been shut down while others not.

func (*Application) Startup

func (app *Application) Startup() error

Startup starts all unstarted microservices included in this app. Microservices that are included together are started in parallel together. Otherwise, microservices are started sequentially in order of inclusion. If an error is returned, there is no guarantee as to the state of the microservices: some microservices may have been started while others not.

func (*Application) WaitForInterrupt

func (app *Application) WaitForInterrupt()

WaitForInterrupt blocks until an interrupt is received through a SIGTERM, SIGINT or a call to interrupt.

Jump to

Keyboard shortcuts

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