JBoss.orgCommunity Documentation

Chapter 10. Services

10.1. What Are Services?
10.2. Service Classes
10.3. Deploying Services
10.3.1. torquebox.yml Services Format
10.4. Clustered Services
10.4.1. Services Running on Every Node
10.4.2. High Availability Singleton Services
10.5. Resource Injection with Services

Services are persistent background Ruby daemons deployed and managed by TorqueBox. Common uses for services include connecting to a remote service (IRC bot, Twitter Streaming API client) or starting a server to listen for incoming connections. A service may be deployed as part of a web application or as its own application without any web component. Services have full access to the entire Ruby environment. This means that a service deployed as part of a web application can interact with database models and other application functionality.

Each service maps to exactly one Ruby class that should optionally implement initialize(Hash), start() and stop() methods which should each return quickly. Typically the start method will spawn a new thread to start an event loop or other long-running task.


Services are deployed by creating a services section inside your application's torquebox.yml.

If a service requires access to other resources, such as messaging topics and queues, or Java CDI components these should be injected using the resource injection facilities provided by TorqueBox (see Chapter 11, Resource Injection).

In order for resource injection to function with services, they must reside either at the root of your application directory (typical for simple Rack applications), or underneath an app/services/ directory. If you place the service anywhere else, it may still funciton, but resources injection will not be available.