Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Camel uses a simple lifecycle interface called Service which has a single start() and stop() method.

...

The CamelContext provides methods to control its lifecycle:

  • start
  • stop
  • suspend Camel 2.5
  • resume Camel 2.5

The operations is paired: start/stop and suspend/resume.

...

Service lifecycle

A service (org.apache.camel.Service) in Camel adheres to the following lifecycle states as illustrated in the diagram below:

...

Notice: A service can optimally support suspend/resume by the org.apache.camel.SuspendableService. This means not all services in Camel supports suspension. It's encouraged that consumers support suspension which allows to suspend/resume routes.

Tip
extend ServiceSupport
extend ServiceSupport

The org.apache.camel.impl.ServiceSupport is a good base class to extend for custom services as it offers the basic functionally to keep track of state. You implement your custom logic in the doStart, doStop, doSuspend, doResume methods.

Routes lifecycle

Routes in Camel have the following operations to control its lifecycle

  • start
  • stop
  • suspend
  • resume
  • remove (previously named shutdown)

The shutdown remove operation will also remove the route, for example in JMX the route will then be unregistered and its gone. So only use shutdown remove if you really want to remove the route. The route must have been stopped before you can remove.

The start and resume operations in JMX checks the state beforehand. So if a route is stopped and you click resume, it will know to invoke start. And likewise if a route has been suspended and you click start it knows to resume instead. This makes management a bit easier.

If a route is suspended then it keeps its resources and all their JMX metrics alive. Where as stopping a route will graceful stop the route, and clear its resources, and as well their JMX metrics. If you want to temporary "pause" a route, then consider using suspend/resume over stop/start.

Info

If a route consumer does not support suspension, it will fallback and stop the route instead.

See Also