...
Name | Type | Description |
---|---|---|
|
| time of the event in millis Version 2.8 |
|
| the map consumer sets here "instancelistener" Version 2.8 |
|
| type of event - here added or removed. Version 2.8 |
|
| host name of the instance Version 2.8 |
|
| port number of the instance Version 2.8 |
Using hazelcast reference
By its name
Code Block | ||
---|---|---|
| ||
<bean id="hazelcastLifecycle" class="com.hazelcast.core.LifecycleService"
factory-bean="hazelcastInstance" factory-method="getLifecycleService"
destroy-method="shutdown" />
<bean id="config" class="com.hazelcast.config.Config">
<constructor-arg type="java.lang.String" value="HZ.INSTANCE" />
</bean>
<bean id="hazelcastInstance" class="com.hazelcast.core.Hazelcast" factory-method="newHazelcastInstance">
<constructor-arg type="com.hazelcast.config.Config" ref="config"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="testHazelcastInstanceBeanRefPut">
<from uri="direct:testHazelcastInstanceBeanRefPut"/>
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<to uri="hazelcast:map:testmap?hazelcastInstanceName=HZ.INSTANCE"/>
</route>
<route id="testHazelcastInstanceBeanRefGet">
<from uri="direct:testHazelcastInstanceBeanRefGet" />
<setHeader headerName="CamelHazelcastOperationType">
<constant>get</constant>
</setHeader>
<to uri="hazelcast:map:testmap?hazelcastInstanceName=HZ.INSTANCE"/>
<to uri="seda:out" />
</route>
</camelContext> |
By instance
Code Block | ||
---|---|---|
| ||
<bean id="hazelcastInstance" class="com.hazelcast.core.Hazelcast"
factory-method="newHazelcastInstance" />
<bean id="hazelcastLifecycle" class="com.hazelcast.core.LifecycleService"
factory-bean="hazelcastInstance" factory-method="getLifecycleService"
destroy-method="shutdown" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="testHazelcastInstanceBeanRefPut">
<from uri="direct:testHazelcastInstanceBeanRefPut"/>
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<to uri="hazelcast:map:testmap?hazelcastInstance=#hazelcastInstance"/>
</route>
<route id="testHazelcastInstanceBeanRefGet">
<from uri="direct:testHazelcastInstanceBeanRefGet" />
<setHeader headerName="CamelHazelcastOperationType">
<constant>get</constant>
</setHeader>
<to uri="hazelcast:map:testmap?hazelcastInstance=#hazelcastInstance"/>
<to uri="seda:out" />
</route>
</camelContext> |
Publishing hazelcast instance as an OSGI service
If operating in an OSGI container and you would want to use one instance of hazelcast across all bundles in the same container. You can publish the instance as an OSGI service and bundles using the cache al need is to reference the service in the hazelcast endpoint.
Bundle A create an instance and publishes it as an OSGI service
Code Block | ||
---|---|---|
| ||
<bean id="config" class="com.hazelcast.config.FileSystemXmlConfig">
<argument type="java.lang.String" value="${hazelcast.config}"/>
</bean>
<bean id="hazelcastInstance" class="com.hazelcast.core.Hazelcast" factory-method="newHazelcastInstance">
<argument type="com.hazelcast.config.Config" ref="config"/>
</bean>
<!-- publishing the hazelcastInstance as a service -->
<service ref="hazelcastInstance" interface="com.hazelcast.core.HazelcastInstance" /> |
Bundle B uses the instance
Code Block | ||
---|---|---|
| ||
<!-- referencing the hazelcastInstance as a service -->
<reference ref="hazelcastInstance" interface="com.hazelcast.core.HazelcastInstance" />
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="testHazelcastInstanceBeanRefPut">
<from uri="direct:testHazelcastInstanceBeanRefPut"/>
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<to uri="hazelcast:map:testmap?hazelcastInstance=#hazelcastInstance"/>
</route>
<route id="testHazelcastInstanceBeanRefGet">
<from uri="direct:testHazelcastInstanceBeanRefGet" />
<setHeader headerName="CamelHazelcastOperationType">
<constant>get</constant>
</setHeader>
<to uri="hazelcast:map:testmap?hazelcastInstance=#hazelcastInstance"/>
<to uri="seda:out" />
</route>
</camelContext> |