Camel Components

Hazelcast Ringbuffer

Since Camel 2.16

Only producer is supported

The Hazelcast ringbuffer component is one of Camel Hazelcast Components which allows you to access Hazelcast ringbuffer. Ringbuffer is a distributed data structure where the data is stored in a ring-like structure. You can think of it as a circular array with a certain capacity.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Hazelcast Ringbuffer component supports the following options which are listed below.

Name Description Default Type

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

hazelcastInstance (advanced)

The Hazelcast instance that the endpoints of this component use when they set none of hazelcastInstance, hazelcastInstanceName, hazelcastConfig and hazelcastConfigUri. Without it, Camel starts a Hazelcast instance for each such endpoint, with the configuration that Hazelcast finds itself (a hazelcast.xml file, or hazelcast-client.xml in client mode, or else the Hazelcast defaults), and shuts it down when the component stops.

HazelcastInstance

hazelcastMode (advanced)

Whether the endpoints start or look up a Hazelcast member (node) or a Hazelcast client (client): in client mode hazelcastInstanceName names a client, and hazelcastConfigUri and hazelcastConfig give a client configuration. Any value other than node means client.

node

String

Endpoint Options

The Hazelcast Ringbuffer endpoint is configured using URI syntax:

hazelcast-ringbuffer:cacheName

With the following path and query parameters:

Path Parameters

Name Description Default Type

cacheName (producer)

Required The name of the Hazelcast data structure: the map, multimap, replicated map, list, set, queue, topic, ringbuffer or PN counter, or the queue of hazelcast-seda. hazelcast-instance does not use it.

String

Query Parameters

Name Description Default Type

defaultOperation (producer)

The operation to perform when the message has no CamelHazelcastOperationType header. Each data structure supports only some of the operations, and another one fails. hazelcast-queue uses add and hazelcast-topic publish when it is not set, and the producers of the other data structures fail without an operation. hazelcast-seda and hazelcast-instance do not use it.

Enum values:

  • put

  • delete

  • get

  • update

  • query

  • getAll

  • clear

  • putIfAbsent

  • addAll

  • removeAll

  • retainAll

  • evict

  • evictAll

  • valueCount

  • containsKey

  • containsValue

  • getKeys

  • removeValue

  • increment

  • decrement

  • setValue

  • destroy

  • compareAndSet

  • getAndAdd

  • add

  • offer

  • peek

  • poll

  • remainingCapacity

  • drainTo

  • removeIf

  • take

  • publish

  • readOnceHead

  • readOnceTail

  • capacity

HazelcastOperation

hazelcastConfigUri (producer)

The location of a Hazelcast XML configuration file (a client configuration when hazelcastMode is client), from which Camel starts a Hazelcast instance for the endpoint. A member configuration that sets an instance name reuses the running member of that name. The file is on the classpath by default; use the file: prefix for a file. Used only when neither hazelcastInstance nor hazelcastInstanceName gives an instance, and when hazelcastConfig is not set.

String

hazelcastInstance (producer)

The Hazelcast instance to use. It takes precedence over hazelcastInstanceName, hazelcastConfig, hazelcastConfigUri and the hazelcastInstance option of the component. Camel does not shut it down.

HazelcastInstance

hazelcastInstanceName (producer)

The name of a Hazelcast instance that is already running in this JVM: a member, or a client when hazelcastMode is client. It takes precedence over hazelcastConfig and hazelcastConfigUri. When no instance has this name, the endpoint gets its instance as if this option was not set.

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

Message Headers

The Hazelcast Ringbuffer component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelHazelcastOperationType (producer)

Constant: OPERATION

The operation to perform, such as put or get, by its name or as a HazelcastOperation: it overrides the defaultOperation option. The producer removes the header afterwards.

String

Message Body

The message body at each side of the Hazelcast Ringbuffer component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Producer input

text, bytes, file, value, map, list or pojo

The item that add appends: an object Hazelcast can serialize, so a stream or no body fails. The other operations do not use the body.

Producer output

unknown

By the operation, which the CamelHazelcastOperationType header sets, or else the defaultOperation option (without either the producer fails): the sequence of the added item as a Long for add, a Long for capacity and remainingCapacity, and the item at the head (readOnceHead) or the tail (readOnceTail) of the ringbuffer.

  • With defaultOperation=add: value (java.lang.Long)

  • With defaultOperation=capacity: value (java.lang.Long)

  • With defaultOperation=remainingCapacity: value (java.lang.Long)

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

ringbuffer cache producer

The ringbuffer producer provides 5 operations:

  • add

  • readOnceHead

  • readOnceTail

  • remainingCapacity

  • capacity

Example for put:

  • Java

  • XML

  • YAML

from("direct:put")
.setHeader("CamelHazelcastOperationType", constant("add"))
.to("hazelcast-ringbuffer:bar");
<route>
    <from uri="direct:put"/>
    <log message="put.."/>
    <setHeader name="CamelHazelcastOperationType">
        <constant>add</constant>
    </setHeader>
    <to uri="hazelcast-ringbuffer:foo"/>
</route>
- route:
    from:
      uri: direct:put
      steps:
        - setHeader:
            name: CamelHazelcastOperationType
            expression:
              constant:
                expression: add
        - to:
            uri: hazelcast-ringbuffer:foo

Example for readonce from head:

  • Java

  • XML

  • YAML

from("direct:get")
    .setHeader("CamelHazelcastOperationType", constant("readOnceHead"))
    .to("hazelcast-ringbuffer:bar")
    .to("seda:out");
<route>
  <from uri="direct:get"/>
  <setHeader name="CamelHazelcastOperationType">
    <constant>readOnceHead</constant>
  </setHeader>
  <to uri="hazelcast-ringbuffer:bar"/>
  <to uri="seda:out"/>
</route>
- route:
    from:
      uri: direct:get
      steps:
        - setHeader:
            name: CamelHazelcastOperationType
            constant: readOnceHead
        - to:
            uri: hazelcast-ringbuffer:bar
        - to:
            uri: seda:out