Skip to main content

Go Embedding

Go services can embed Orisun directly instead of running the gRPC server as a separate process.

Backend-specific embedding packages keep deployments explicit:

  • embedded/postgres imports the PostgreSQL backend.
  • embedded/sqlite imports the SQLite backend.
  • Neither package needs the unused backend.

Use embedding when Orisun should be part of your service process. Use the standalone server when you want a separate operational boundary and language-agnostic gRPC access.

PostgreSQL Embedding

import (
"context"

embeddedpg "github.com/oexza/Orisun/embedded/postgres"
"github.com/oexza/Orisun/config"
"github.com/oexza/Orisun/logging"
)

func start(ctx context.Context) (*embeddedpg.Store, error) {
cfg := config.InitializeConfig()
cfg.Backend.Type = "postgres"
logger := logging.InitializeDefaultLogger(cfg.Logging)
return embeddedpg.Start(ctx, cfg, logger)
}

SQLite Embedding

import (
"context"

embeddedsqlite "github.com/oexza/Orisun/embedded/sqlite"
"github.com/oexza/Orisun/config"
"github.com/oexza/Orisun/logging"
)

func start(ctx context.Context) (*embeddedsqlite.Store, error) {
cfg := config.InitializeConfig()
cfg.Backend.Type = "sqlite"
cfg.Nats.Cluster.Enabled = false
logger := logging.InitializeDefaultLogger(cfg.Logging)
return embeddedsqlite.Start(ctx, cfg, logger)
}

Embedded Index Management

Embedded stores expose boundary index management directly. Applications do not need to expose Admin to create JSON expression indexes.

err := store.CreateBoundaryIndex(
ctx,
"orders",
"customer_id",
[]orisun.BoundaryIndexField{
{JsonKey: "customer_id", ValueType: "text"},
},
nil,
orisun.IndexCombinatorAND,
)

Capabilities

Embedded stores expose the same high-level behavior as the server:

  • save events
  • query events
  • subscribe to events
  • create and drop boundary indexes
  • preserve backend-specific publishing guarantees

Shutdown

Call the store's close method during service shutdown so database pools, NATS resources, and background loops can stop cleanly.