You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Camel Ignite component

Available as of Camel 2.17

Apache Ignite In-Memory Data Fabric is a high-performance, integrated and distributed in-memory platform for computing and transacting on large-scale data sets in real-time, orders of magnitude faster than possible with traditional disk-based or flash technologies. It is designed to deliver uncompromised performance for a wide set of in-memory computing use cases from high performance computing, to the industry most advanced data grid, highly available service grid, and streaming. See all features.

This component offers seven endpoints to cover much of Ignite's functionality:

  • Ignite Cache.
  • Ignite Compute.
  • Ignite Messaging.
  • Ignite Events.
  • Ignite Sets.
  • Ignite Queues.
  • Ignite ID Generator.

To use this component, add the following dependency to your pom.xml:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-ignite</artifactId>
    <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
</dependency>

URI formats

ignite:cache:cacheName?options

ignite:compute:endpointId?options
ignite:messaging:topicName?options
ignite:events:endpointId?options
ignite:sets:setName?options
ignite:queue:queueName?options
ignite:idgen:sequenceName?options

Initializing the Ignite component

Each instance of the Ignite component is associated with an underlying org.apache.ignite.Ignite instance. You can interact with two Ignite clusters by initializing two instances of the Ignite component and binding them to different IgniteConfigurations. There are 3 ways to initialize the Ignite component:

  • By passing in an existing org.apache.ignite.Ignite instance. Here's an example using Spring config:
<bean name="ignite" class="org.apache.camel.component.ignite.IgniteComponent">
   <property name="ignite" ref="ignite" />
</bean>
  • By passing in an IgniteConfiguration, either constructed programmatically or through inversion of control (e.g. Spring, Blueprint, etc.). Here's an example using Spring config:
<bean name="ignite" class="org.apache.camel.component.ignite.IgniteComponent">
   <property name="igniteConfiguration">
      <bean class="org.apache.ignite.configuration.IgniteConfiguration">
         [...]
      </bean>
   </property>
</bean>
  • By passing in a URL, InputStream or String URL to a Spring-based configuration file. In all three cases, you inject them in the same property called configurationResource. Here's an example using Spring config:
<bean name="ignite" class="org.apache.camel.component.ignite.IgniteComponent">
   <property name="configurationResource" value="file:[...]/ignite-config.xml" />
</bean>


Additionally, if using Camel programmatically, there are several convenience static methods in IgniteComponent that return a component out of any of these configuration options:

  • IgniteComponent#fromIgnite(Ignite)
  • IgniteComponent#fromConfiguration(IgniteConfiguration)
  • IgniteComponent#fromInputStream(InputStream)
  • IgniteComponent#fromUrl(URL)
  • IgniteComponent#fromLocation(String)

General options

All endpoints share the following options:

OptionTypeDefault valueDescription
propagateIncomingBodyIfNoReturnValuebooleantrue 
treatCollectionsAsCacheObjectsbooleanfalse 

 

Usage

As AMQP component is inherited from JMS component, the usage of the former is almost identical to the latter:

Using AMQP component
// Consuming from AMQP queue
from("amqp:queue:incoming").
  to(...);
 
// Sending message to the AMQP topic
from(...).
  to("amqp:topic:notify");

Configuring AMQP component

Starting from the Camel 2.16.1 you can also use the AMQPComponent#amqp10Component(String connectionURI) factory method to return the AMQP 1.0 component with the pre-configured topic prefix: 

Creating AMQP 1.0 component
 AMQPComponent amqp = AMQPComponent.amqp10Component("amqp://guest:guest@localhost:5672");

Keep in mind that starting from the Camel 2.17 the AMQPComponent#amqp10Component(String connectionURI) factory method has been deprecated on the behalf of the AMQPComponent#amqpComponent(String connectionURI)

Creating AMQP 1.0 component
AMQPComponent amqp = AMQPComponent.amqpComponent("amqp://localhost:5672");
 
AMQPComponent authorizedAmqp = AMQPComponent.amqpComponent("amqp://localhost:5672", "user", "password");

Starting from Camel 2.17, in order to automatically configure the AMQP component, you can also add an instance of org.apache.camel.component.amqp.AMQPConnectionDetails to the registry. For example for Spring Boot you just have to define bean:

AMQP connection details auto-configuration
@Bean
AMQPConnectionDetails amqpConnection() {
  return new AMQPConnectionDetails("amqp://lcoalhost:5672"); 
}
 
@Bean
AMQPConnectionDetails securedAmqpConnection() {
  return new AMQPConnectionDetails("amqp://lcoalhost:5672", "username", "password"); 
}

 

You can also rely on the Camel properties to read the AMQP connection details. Factory method AMQPConnectionDetails.discoverAMQP() attempts to read Camel properties in a Kubernetes-like convention, just as demonstrated on the snippet below:

 

AMQP connection details auto-configuration
export AMQP_SERVICE_HOST = "mybroker.com"
export AMQP_SERVICE_PORT = "6666"
export AMQP_SERVICE_USERNAME = "username"
export AMQP_SERVICE_PASSWORD = "password"
 
...
 
@Bean
AMQPConnectionDetails amqpConnection() {
  return AMQPConnectionDetails.discoverAMQP(); 
}

Using topics

To have using topics working with camel-amqp you need to configure the component to use topic:// as topic prefix, as shown below:

 <bean id="amqp" class="org.apache.camel.component.amqp.AmqpComponent">
        <property name="connectionFactory">
          <bean class="org.apache.qpid.amqp_1_0.jms.impl.ConnectionFactoryImpl" factory-method="createFromURL">
            <constructor-arg index="0" type="java.lang.String" value="amqp://localhost:5672" />
            <property name="topicPrefix" value="topic://" />  <!-- only necessary when connecting to ActiveMQ over AMQP 1.0 -->
          </bean>
        </property>
 </bean>

Keep in mind that both  AMQPComponent#amqpComponent() methods and AMQPConnectionDetails pre-configure the component with the topic prefix, so you don't have to configure it explicitly.

  • No labels