application

package
v1.45.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 13 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. A unique plane of communication is used to isolate the app if it is running in a unit test 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] or [Run] is required. Microservices that are added together are started in parallel. 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.Run()

func (*Application) AddAndStartup

func (app *Application) AddAndStartup(ctx context.Context, services ...service.Service) (err error)

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

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. Defaults: 120 seconds for startup and 24 seconds for shutdown. The 24-second shutdown budget sits under Kubernetes' 30-second default terminationGracePeriodSeconds, leaving ~6 seconds for the runtime and orchestrator to finalize before SIGKILL. Kubernetes does not impose a comparable hard ceiling on startup (startup probes and progressDeadlineSeconds are operator-tuned and much longer), so 120 seconds gives microservices headroom to warm caches, load ML models, or wait on slow dependencies. Override either via the env vars MICROBUS_STARTUP_TIME_BUDGET / MICROBUS_SHUTDOWN_TIME_BUDGET. The chosen budget is applied as a deadline on the ctx passed to each microservice's OnStartup / OnShutdown. For programmatic control, use Application.Startup and Application.Shutdown directly.

func (*Application) RunInTest added in v1.17.0

func (app *Application) RunInTest(t testing.TB) error

RunInTest starts up all microservices included in this app, waits for the test to finish, then shuts them down. A random plane of communication is used to isolate the testing app from other apps. Errors in startup or shutdown will fail the test.

func (*Application) Shutdown

func (app *Application) Shutdown(ctx context.Context) 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. The context deadline is used to limit the time allotted to the operation.

func (*Application) Startup

func (app *Application) Startup(ctx context.Context) 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. The context deadline is used to limit the time allotted to the operation.

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