Documentation
¶
Overview ¶
Package simple provides basic in-memory implementations of the Cache, Queue, NoSQLDB, and RelationalDB backends that are used by workflow services.
The simple backend implementations are alternatives to the heavyweight "full system" implementations such as memcached, rabbitmq, mongodb, mysql, etc.
The simple backend implementations are in-memory data structures; they must reside within the same process as the services that use them.
Wiring Spec Usage ¶
To instantiate a simple backend in your wiring spec, use the corresponding method for the backend type, giving the backend instance a name:
simple.NoSQLDB(spec, "my_nosql_db") simple.RelationalDB(spec, "my_relational_db") simple.Queue(spec, "my_queue") simple.Cache(spec, "my_cache")
After instantiating a backend, it can be provided as argument to a workflow service.
Wiring Spec Example ¶
Consider the SockShop User Service which makes use of a `backend.NoSQLDatabase`. The service has the following constructor:
func NewUserServiceImpl(ctx context.Context, user_db backend.NoSQLDatabase) (UserService, error)
In the wiring spec, we can instantiate the service and provide it with a simple NoSQLDB as follows:
user_db := simple.NoSQLDB(spec, "user_db") user_service := workflow.Service[user.UserService](spec, "user_service", user_db)
Description ¶
The simple implementations are just in-memory data structures, so they can't be shared by services running in different processes. You will encounter a compilation error if you attempt to do so.
The simple implementations are primarily handy when developing and testing workflows, as they avoiding having to deploy full-fledged applications. However, they do not necessarily implement all features (e.g. all operators of a query language), so in some cases they may be insufficient and you might need to resort to testing using proper backends.
Implementations of the backends can be found in the following locations:
- NoSQLDB: runtime/plugins/simplenosqldb
- RelationalDB: runtime/plugins/sqlitereldb
- Queue: runtime/plugins/simplequeue
- Cache: runtime/plugins/simplecache
Index ¶
- func Cache(spec wiring.WiringSpec, name string) string
- func NoSQLDB(spec wiring.WiringSpec, name string) string
- func Queue(spec wiring.WiringSpec, name string) string
- func RelationalDB(spec wiring.WiringSpec, name string) string
- type SimpleBackend
- func (node *SimpleBackend) AddInstantiation(builder golang.NamespaceBuilder) error
- func (node *SimpleBackend) AddInterfaces(builder golang.ModuleBuilder) error
- func (node *SimpleBackend) AddToWorkspace(builder golang.WorkspaceBuilder) error
- func (node *SimpleBackend) GetInterface(ctx ir.BuildContext) (service.ServiceInterface, error)
- func (node *SimpleBackend) ImplementsGolangNode()
- func (node *SimpleBackend) ImplementsGolangService()
- func (node *SimpleBackend) Name() string
- func (node *SimpleBackend) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cache ¶
func Cache(spec wiring.WiringSpec, name string) string
Cache can be used by wiring specs to create an in-memory backend.Cache instance with the specified name. In the compiled application, uses the simplecache.SimpleCache implementation from the Blueprint runtime package
func NoSQLDB ¶
func NoSQLDB(spec wiring.WiringSpec, name string) string
NoSQLDB can be used by wiring specs to create an in-memory backend.NoSQLDatabase instance with the specified name. In the compiled application, uses the simplenosqldb.SimpleNoSQLDB implementation from the Blueprint runtime package The SimpleNoSQLDB has limited support for query and update operations.
func Queue ¶
func Queue(spec wiring.WiringSpec, name string) string
Queue can be used by wiring specs to create an in-memory backend.Queue instance with the specified name. In the compiled application, uses the simplequeue.SimpleQueue implementation from the Blueprint runtime package
func RelationalDB ¶
func RelationalDB(spec wiring.WiringSpec, name string) string
RelationalDB can be used by wiring specs to create an in-memory backend.RelationalDB instance with the specified name. In the compiled application, uses the sqlitereldb.SqliteRelDB implementation from the Blueprint runtime package The compiled application might fail to run if gcc is not installed and CGO_ENABLED is not set.
Types ¶
type SimpleBackend ¶
type SimpleBackend struct { golang.Service // Interfaces for generating Golang artifacts golang.ProvidesModule golang.ProvidesInterface golang.Instantiable InstanceName string BackendType string // e.g. "NoSQLDatabase" BackendImpl string // e.g. "SimpleNoSQLDB" Spec *workflowspec.Service // The backend's interface and implementation }
The SimpleBackend IR node represents a service or backend implementation that is wholly defined in Blueprint's runtime module. Examples include SimpleCache, SimpleNoSQLDB, etc.
The compiled SimpleBackend node will simply include the runtime module in the compiled output, and create instances of the service / backend by calling the appropriate constructors from the runtime module.
func (*SimpleBackend) AddInstantiation ¶
func (node *SimpleBackend) AddInstantiation(builder golang.NamespaceBuilder) error
Ipmlements golang.Instantiable
func (*SimpleBackend) AddInterfaces ¶
func (node *SimpleBackend) AddInterfaces(builder golang.ModuleBuilder) error
Implements golang.ProvidesInterface
func (*SimpleBackend) AddToWorkspace ¶
func (node *SimpleBackend) AddToWorkspace(builder golang.WorkspaceBuilder) error
Implements golang.ProvidesModule
func (*SimpleBackend) GetInterface ¶
func (node *SimpleBackend) GetInterface(ctx ir.BuildContext) (service.ServiceInterface, error)
Implements golang.Service
func (*SimpleBackend) ImplementsGolangNode ¶
func (node *SimpleBackend) ImplementsGolangNode()
func (*SimpleBackend) ImplementsGolangService ¶
func (node *SimpleBackend) ImplementsGolangService()