Resources
A named queue, cache, disk, bus, mailer, or database connection gives your app a stable way to use configured infrastructure. The photo job sends work to the default queue. Give it a named photos queue when it needs its own worker count or backend.
Give the Photo Queue Its Own Settings
The default queue reads QUEUE_* settings. A named photos queue reads its QUEUE_PHOTOS_* overrides. In the app from Run a Photo Job, stop the development watcher and run these commands from the Project root.
forj make:queue photos --workers 2 &&
forj buildThe command writes QUEUE_PHOTOS_NAME=photos and QUEUE_PHOTOS_WORKERS=2 in .env. The build adds Photos() to internal/queues/accessors_gen.go. The queue now has its own two-worker allocation. Its driver follows QUEUE_DRIVER unless QUEUE_PHOTOS_DRIVER overrides it.
GoForj also generates named caches, storage disks, event buses, mailers, and database connections when their components are enabled. Named Resource Conventions lists their prefixes and naming rules.
Dispatch by Logical Name
In internal/photos/check_job.go, change OnQueue("default") to OnQueue("photos") in CheckJob.Queue. Keep dispatching through the injected *queues.Manager. The manager resolves the logical name to the named runtime's driver and physical backend queue name. Photos() is the direct runtime handle for inspection and worker lifecycle.
Start forj dev, then send another photo check from a second terminal. Expect the same 202 Accepted response and a photo checked log with the saved photo's ID. Run forj about to confirm that photos has the expected driver and two workers.
In an additional app, the manager prefixes physical queue names with the app name. A logical photos queue in admin becomes admin_photos by default. Keep OnQueue("photos") in application code so dispatch uses that translation.
Know Which Change Needs a Build
Adding or renaming a resource changes the compiled accessors and requires forj build. Named accessors fail fast when their expected resource is absent from runtime configuration. Check the enabled component and named settings, then rebuild to keep configuration and accessors aligned. Enabled components also expose managers such as app.DB() and app.Queues(). Services receive the manager they need through a constructor.
Selecting a driver already compiled into the app requires runtime settings and a restart. Adding driver support requires a new build. Before switching a queue backend, coordinate producers and drain or migrate outstanding work. Existing jobs stay in the old backend. Follow Apply a Driver Change for that operation.
Keep Names Stable
Use names such as photos, sessions, and uploads for a bounded purpose across configuration, accessors, and operational tools. Jobs, schedules, and routes have their own registration names. Naming Conventions distinguishes those identifiers.
Resource names can be metric labels. Keep user IDs, email addresses, and payload values out of names and labels so each new request does not create another resource or metric series.
Drivers and HTTP Adapters
A driver implements a backend behind the API your service uses. A named uploads disk can use local storage during development and S3 in production. Providers construct the storage manager and its drivers from configuration. Inject the manager into your service and keep backend credentials and connection settings in that construction.
An HTTP adapter translates between contracts. GoForj's web/adapter/echoweb adapter connects web.Context to Echo. The HTTP server constructs it in internal/http/server.go. HTTP Runtime covers server customization.
Backends can differ in latency, URL support, permissions, and failure behavior even when the service uses the same API. See Driver Selection for how to choose and Driver Options for the accepted values.
Local, Shared, and Durable Resources
Start with dependencies you can run on your machine. Save and List Photos uses SQLite, and Run a Photo Job adds a worker in the same process. Run forj dev from the Project root to build and run the apps enrolled under dev.apps. Local Development covers the watcher and rebuild behavior.
| Resource | Local Choice | Constraint |
|---|---|---|
| Database | SQLite | Records live in the configured file. |
| Storage | Local disk | Other machines need access to the same files. |
| Cache | Memory or file | Memory belongs to one process. |
| Queue | workerpool | Pending work is lost on process restart. |
| Events | In-process bus | Subscribers receive events within that process. |
| Log driver or local SMTP | Verify actual delivery with the selected provider. |
Use the sync queue driver when a test or workflow needs inline execution. Local drivers apply to enabled components.
Separate API and worker processes need a queue they can both reach. Replicas serving the same uploads need shared storage. Cross-process event subscribers need a transport that reaches them. Choose durable infrastructure when data or work must survive a restart. Shared access and durability are separate properties. Check persistence, retries, and delivery behavior for the selected backend.
Use Runtime Topology to run the App directly or choose separate processes. Driver Selection covers verification across those boundaries.