LibraryLink ToToggle FramesPrintFeedback

Defining a Standalone Main Method

In the case of a standalone deployment, the application developer to creates, configures and starts a CamelContext instance (which encapsulates the core of the router functionality). For this purpose, you should define a main() method that performs the following key tasks:

Example 1.1 shows the standard outline of a standalone main() method, which is defined in an example class, CamelJmsToFileExample. This example shows how to initialize and activate a CamelContext instance.


The code in Example 1.1 does the following:

1

Define a static main() method to serve as the entry point for running the standalone router.

2

Instantiates a CamelContext instance explicitly. There is just one implementation of CamelContext currently available, the DefaultCamelContext class.

3

Adds any components that are required to the CamelContext (see Adding Components to the Camel Context).

4

Adds the RouteBuilder objects to the CamelContext (see Adding RouteBuilders to the CamelContext).

5

The CamelContext.start() method creates a new thread and starts to process incoming messages using the registered routing rules. If the main thread now exits, the CamelContext sub-thread remains active and continues to process messages. Typically, you can stop the router by typing Ctrl+C in the window where you launched the router application (or by sending a kill signal in UNIX). If you want more control over stopping the router process, you can use the CamelContext.stop() method in combination with an instrumentation library (such as JMX).