concept Hazelcast in category camel

appears as: Hazelcast
Camel in Action

This is an excerpt from Manning's book Camel in Action.

Other implementations such as SQL and JPA require you to manually delete unwanted records from the database table. In-memory data grids such as Hazelcast, Infinispan, and JCache provide configurations for setting the eviction strategy.

Listing 12.13 A standalone Java Camel application with Hazelcast embedded
public class ServerFoo { private Main main; public static void main(String[] args) throws Exception { ServerFoo foo = new ServerFoo(); foo.boot();     #1 } public void boot() throws Exception { HazelcastInstance hz = Hazelcast.newHazelcastInstance();     #2 HazelcastIdempotentRepository repo = new HazelcastIdempotentRepository(hz, "camel");     #3 main = new Main(); main.enableHangupSupport(); main.bind("myRepo", repo);     #4 main.addRouteBuilder(new FileConsumerRoute("FOO", 100));     #5 main.run(); } } #1 ServerFoo is a standalone Java application with a main method to boot the application. #2 Creates and embeds a Hazelcast instance in server mode #3 Sets up Camel Hazelcast idempotent repository using the name camel #4 Binds the idempotent repository to the Camel registry with the name myRepo #5 Adds a Camel route from Java code and runs the application

Each node is a standalone Java application with a main method ❶. Hazelcast is configured using the XML file src/main/resources/hazelcast.xml. Then you embed and create a Hazelcast instance ❷, which by default reads its configuration from the root classpath as the name hazelcast.xml. At this point, Hazelcast is starting up and therefore is ready to use the Hazelcast idempotent repository created ❸. The remainder of the code uses Camel Main to easily configure (❹ ❺) and embed a Camel application with the route.

Figure 17.7 A user accesses a distributed Camel application that has been clustered and runs on two nodes (❷, ❺). The application stores state about user activity, which is made available at all times using the clustered cache provided, such as Hazelcast ❸.

c17_07.png