Apache Flume is a distributed, reliable, and available service for efficiently collecting, aggregating, and moving large amounts of event data. It has a simple and flexible architecture based on streaming data flows. It is robust and fault tolerant with tunable reliability mechanisms and many failover and recovery mechanisms. The system is centrally managed and allows for intelligent dynamic management. It uses a simple extensible data model that allows for online analytic application.
Apache Flume JMS provides the JMS Source, which reads messages from a JMS queue or topic.
It is selected with the jms source type.
Apache Flume JMS is open-sourced under the Apache Software Foundation License v2.0.
The body of a JMS ObjectMessage is a serialized Java object. Deserializing data from
an untrusted source is dangerous: anyone who can publish to the destination could send
a payload that runs code in the Flume agent while it is being deserialized.
The JMS Source therefore only deserializes the classes that are explicitly allowed. By default these are:
- the boxed primitives (
Boolean,Byte,Character,Short,Integer,Long,FloatandDouble), String,BigIntegerandBigDecimal,- arrays of primitives or of allowed classes.
A message that contains any other class is rejected: a warning naming the rejected class is logged and the JMS transaction is rolled back, together with the rest of the batch. The broker then redelivers the message, so a rejected message blocks the destination until the broker's redelivery policy gives up on it, typically by moving it to a dead letter queue. Make sure such a policy is configured before relying on rejection.
To receive ObjectMessages that carry your own classes, implement
org.apache.flume.source.jms.JMSObjectMessageClassProvider:
package com.example.flume;
import com.example.model.Order;
import com.example.model.OrderLine;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.apache.flume.source.jms.JMSObjectMessageClassProvider;
public final class OrderClassProvider implements JMSObjectMessageClassProvider {
@Override
public Collection<Class<?>> getAllowedClasses() {
// `Order` has a `List<OrderLine>` field, holding an `ArrayList`
return Arrays.asList(Order.class, OrderLine.class, ArrayList.class);
}
}Providers are discovered with java.util.ServiceLoader. Register yours in a file named
META-INF/services/org.apache.flume.source.jms.JMSObjectMessageClassProvider:
com.example.flume.OrderClassProvider
If your code runs on the module path, declare the provider in your module-info.java instead:
module com.example.flume {
requires org.apache.flume.flume.jms.source;
provides org.apache.flume.source.jms.JMSObjectMessageClassProvider with com.example.flume.OrderClassProvider;
}Put the JAR with your provider and your classes on the agent's class path, for example in
the agent's plugins.d directory, next to the JMS Source. The classes allowed by all the
providers that are found are combined. Providers are only loaded once, when the first
ObjectMessage is received, so the agent must be restarted to pick up changes.
The allow-list is checked for every class in the deserialized object graph, not just the class of the message body:
- Superclasses of a registered class are allowed automatically, since they are part of its serialized form.
- Field types must be registered separately. A field declared as
Listthat holds anArrayListrequiresArrayList; aMapfield holding aHashMaprequiresHashMap. Fields of the default types (String,Integer, etc.) and primitive fields need nothing. - Arrays are allowed when their element type is primitive or allowed.
Only register classes that are safe to deserialize: never register classes whose
readObject, readResolve or similar methods have side effects, and avoid registering
broad, general-purpose types you do not need.
The JMS Source converts messages with a JMSMessageConverter. The default converter applies
the allow-list automatically. A custom converter must call
JMSObjectMessageFilter.getObject(message) instead of message.getObject(); calling
getObject() directly bypasses the allow-list.
The JMS client library deserializes the body itself, inside ObjectMessage.getObject(), so
Flume never sees the serialized stream. The only portable way to restrict it is the JVM-wide
deserialization filter factory
introduced in Java 17. JMSObjectMessageFilter is that factory: it applies the allow-list
only to the streams created by the thread that is reading an ObjectMessage, and only while
it does so. All other deserialization in the agent is left to the filters it would have had
otherwise, and a JVM-wide filter set with -Djdk.serialFilter still applies on top of the
allow-list.
This has the following limitations:
-
The filter factory can only be installed once per JVM, and only before any object has been deserialized. The JMS Source installs it when it is configured, early in the agent's startup. If another component deserialized something first, or another filter factory is already installed, the JMS Source logs a warning and rejects every
ObjectMessagerather than reading them unfiltered. In that case, install the factory when the JVM starts, for example inJAVA_OPTSinflume-env.sh:-Djdk.serialFilterFactory=org.apache.flume.source.jms.JMSObjectMessageFilterThe JMS Source JAR must then be on the JVM's class path. This option cannot be combined with another filter factory.
-
The JMS client must deserialize the body on the thread that calls
getObject(). This is the usual behavior and is verified with ActiveMQ. A client that deserializes messages eagerly on its own threads, before Flume reads them, is not protected by the allow-list. Use the JMS client's own protections as well where they exist, such astrustedPackagesin ActiveMQ or thedeserializationAllowListin ActiveMQ Artemis. -
The event body is the object serialized again, so whatever consumes the events must also deserialize it. Apply the same care there.
TextMessages and BytesMessages are not affected by any of this. If you control the producers,
prefer them to ObjectMessages.
The Flume 2.x guide and FAQ are available here:
- Mailing lists: https://cwiki.apache.org/confluence/display/FLUME/Mailing+Lists
- Slack channel #flume on https://the-asf.slack.com/
Bug and Issue tracker.
Compiling Flume JMS requires the following tools:
- Java JDK 17
- Apache Maven 3.x
Build it with:
./mvnw verify