Flume JMS User Guide
JMS Source
JMS Source reads messages from a JMS destination such as a queue or topic. Being a JMS application it should work with any JMS provider but has only been tested with ActiveMQ. The JMS source provides configurable batch size, message selector, user/pass, and message to flume event converter. Note that the vendor provided JMS jars should be included in the Flume classpath using plugins.d directory (preferred), --classpath on command line, or via FLUME_CLASSPATH variable in flume-env.sh.
Required properties are in bold.
| Property Name | Default | Description |
|---|---|---|
channels |
— |
|
type |
— |
The component type name, needs to be |
initialContextFactory |
— |
Inital Context Factory, e.g: org.apache.activemq.jndi.ActiveMQInitialContextFactory |
connectionFactory |
— |
The JNDI name the connection factory should appear as |
providerURL |
— |
The JMS provider URL |
destinationName |
— |
Destination name |
destinationType |
— |
Destination type (queue or topic) |
messageSelector |
— |
Message selector to use when creating the consumer |
userName |
— |
Username for the destination/provider |
passwordFile |
— |
File containing the password for the destination/provider |
batchSize |
100 |
Number of messages to consume in one batch |
converter.type |
DEFAULT |
Class to use to convert messages to flume events. See below. |
converter.* |
— |
Converter properties. |
converter.charset |
UTF-8 |
Default converter only. Charset to use when converting JMS TextMessages to byte arrays. |
createDurableSubscription |
false |
Whether to create durable subscription. Durable subscription can only be used with destinationType topic. If true, "clientId" and "durableSubscriptionName" have to be specified. |
clientId |
— |
JMS client identifier set on Connection right after it is created. Required for durable subscriptions. |
durableSubscriptionName |
— |
Name used to identify the durable subscription. Required for durable subscriptions. |
JMS message converter
The JMS source allows pluggable converters, though it’s likely the default converter will work for most purposes. The default converter is able to convert Bytes, Text, and Object messages to FlumeEvents. In all cases, the properties in the message are added as headers to the FlumeEvent.
- BytesMessage
-
Bytes of message are copied to body of the FlumeEvent. Cannot convert more than 2GB of data per message.
- TextMessage
-
Text of message is converted to a byte array and copied to the body of the FlumeEvent. The default converter uses UTF-8 by default but this is configurable.
- ObjectMessage
-
Object is written out to a ByteArrayOutputStream wrapped in an ObjectOutputStream and the resulting array is copied to the body of the FlumeEvent.
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.
Allowing your own classes
To receive ObjectMessage`s 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.
Which classes must be registered
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.
Custom message converters
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.
How it works and its limitations
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.JMSObjectMessageFilter ```
The 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.
`TextMessage`s and `BytesMessage`s are not affected by any of this. If you control the producers, prefer them to `ObjectMessage`s.
Example for agent named a1:
-
Properties
-
YAML
-
JSON
a1.sources = r1
a1.channels = c1
a1.sources.r1.type = jms
a1.sources.r1.channels = c1
a1.sources.r1.initialContextFactory = org.apache.activemq.jndi.ActiveMQInitialContextFactory
a1.sources.r1.connectionFactory = GenericConnectionFactory
a1.sources.r1.providerURL = tcp://mqserver:61616
a1.sources.r1.destinationName = BUSINESS_DATA
a1.sources.r1.destinationType = QUEUE
a1:
sources:
r1:
type: jms
channels: c1
initialContextFactory: org.apache.activemq.jndi.ActiveMQInitialContextFactory
connectionFactory: GenericConnectionFactory
providerURL: tcp://mqserver:61616
destinationName: BUSINESS_DATA
destinationType: QUEUE
channels: c1
"a1": {
"sources": {
"r1": {
"type": "jms",
"channels": "c1",
"initialContextFactory": "org.apache.activemq.jndi.ActiveMQInitialContextFactory",
"connectionFactory": "GenericConnectionFactory",
"providerURL": "tcp://mqserver:61616",
"destinationName": "BUSINESS_DATA",
"destinationType": "QUEUE"
}
},
"channels": "c1"
}
SSL and JMS Source
JMS client implementations typically support to configure SSL/TLS via some Java system properties defined by JSSE (Java Secure Socket Extension). Specifying these system properties for Flume’s JVM, JMS Source (or more precisely the JMS client implementation used by the JMS Source) can connect to the JMS server through SSL (of course only when the JMS server has also been set up to use SSL). It should work with any JMS provider and has been tested with ActiveMQ, IBM MQ and Oracle WebLogic.
The following sections describe the SSL configuration steps needed on the Flume side only. You can find more detailed descriptions about the server side setup of the different JMS providers and also full working configuration examples on Flume Wiki.
SSL transport / server authentication:
If the JMS server uses self-signed certificate or its certificate is signed by a non-trusted CA (eg. the company’s own CA), then a truststore (containing the right certificate) needs to be set up and passed to Flume. It can be done via the global SSL parameters. For more details about the global SSL setup, see the SSL/TLS support section.
Some JMS providers require SSL specific JNDI Initial Context Factory and/or Provider URL settings when using SSL (eg.
ActiveMQ uses ssl:// URL prefix instead of tcp://).
In this case the source properties (initialContextFactory and/or providerURL) have to be adjusted in the agent
config file.
Client certificate authentication (two-way SSL):
JMS Source can authenticate to the JMS server through client certificate authentication instead of the usual user/password login (when SSL is used and the JMS server is configured to accept this kind of authentication).
The keystore containing Flume’s key used for the authentication needs to be configured via the global SSL parameters again. For more details about the global SSL setup, see the SSL/TLS support section.
The keystore should contain only one key (if multiple keys are present, then the first one will be used). The key password must be the same as the keystore password.
In case of client certificate authentication, it is not needed to specify the userName / passwordFile properties
for the JMS Source in the Flume agent config file.
Please note:
There are no component level configuration parameters for JMS Source unlike in case of other components. No enable SSL flag either. SSL setup is controlled by JNDI/Provider URL settings (ultimately the JMS server settings) and by the presence / absence of the truststore / keystore.