Description:

This ControllerService allows users to reference a JMS Connection Factory that has already been established and made available via Java Naming and Directory Interface (JNDI) Server. Please see documentation from your JMS Vendor in order to understand the appropriate values to configure for this service.

A Connection Factory in Java is typically obtained via JNDI in code like below. The comments have been added in to explain how this maps to the Controller Service's configuration.


Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_NAMING_FACTORY_CLASS); // Value for this comes from the "Initial Naming Factory Class" property.
env.put(Context.PROVIDER_URL, NAMING_PROVIDER_URL); // Value for this comes from the "Naming Provider URL" property.
env.put("My-Environment-Variable", "Environment-Variable-Value"); // This is accomplished by added a user-defined property with name "My-Environment-Variable" and value "Environment-Variable-Value"

Context initialContext = new InitialContext(env);
ConnectionFactory connectionFactory = initialContext.lookup(CONNECTION_FACTORY_NAME); // Value for Connection Factory name comes from "Connection Factory Name" property

It is also important to note that, in order for this to work, the class named by the Initial Naming Factory Class must be available on the classpath. In NiFi, this is accomplished by setting the "Naming Factory Libraries" property to point to one or more .jar files or directories (comma-separated values).

When the Controller Service is disabled and then re-enabled, it will perform the JNDI lookup again. Once the Connection Factory has been obtained, though, it will not perform another JNDI lookup until the service is disabled.

Example:

As an example, the following configuration may be used to connect to Active MQ's JMS Broker, using the Connection Factory provided via their embedded JNDI server:

Property Name Property Value
Initial Naming Factory Class org.apache.activemq.jndi.ActiveMQInitialContextFactory
Naming Provider URL tcp://jms-broker:61616
Connection Factory Name ConnectionFactory
Naming Factory Libraries /opt/apache-activemq-5.15.2/lib/

The above example assumes that there exists as host that is accessible with hostname "jms-broker" and that is running Apache ActiveMQ on port 61616 and also that the jar containing the org.apache.activemq.jndi.ActiveMQInitialContextFactory class can be found within the /opt/apache-activemq-5.15.2/lib/ directory.