1
votes

I have a deployed queue on JBoss EAP 7.1 (defined in standalone.xml) that is managed by ActiveMQ Artemis (name of the module xmlns="urn:jboss:domain:messaging-activemq:2.0") and at the same time I want to connect to that queue with the JMS plugin in logstash (with JNDI) for consuming the messages that are sent by the deployed app on my JBoss server, but when I try I get a NameNotFoundException for the connection factory (the property jndi_name in the logstash conf file).

I tried to find the default connection factories JNDI entries but even then it didn't work.

So i want to know if the connection factories are created by the message broker or exist by default for the client? Because if I'm not mistaken, the connection factory is the only way to connect to the broker and the queue and correct if I'm wrong please but they have to exist by default for the client.

I hope you can help me guys here is my logstash conf file:

input {
    jms {
        # Logstash Configuration Settings. 
        include_header => false
        include_properties => false
        include_body => true
        use_jms_timestamp => false
        destination => "AuditTrailMDB"
        pub_sub => false
        # JNDI Settings
        jndi_name => 'queueConnectionFactory'
        jndi_context => { 
         'java.naming.factory.initial' => 'org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory'
         'java.naming.security.principal' => 'admin'
         'java.naming.provider.url' => 'tcp://localhost:5445?type=QUEUE_CF'
         'java.naming.security.credentials' => 'admin'
        }
        # Jar files to be imported
        require_jars=> ['/home/Alternant/logstash/dependencies/jboss-client.jar', 
                        '/home/Alternant/logstash/dependencies/artemis-ra.jar',
                        '/home/Alternant/logstash/dependencies/ironjacamar-core-impl.jar',
                        '/home/Alternant/logstash/dependencies/ironjacamar-core-api.jar',
                        '/home/Alternant/logstash/dependencies/ironjacamar-common-api.jar']
    }
 }output{
     stdout{}
 }

and here is my queue definition in the standalone.xml:

<subsystem xmlns="urn:jboss:domain:messaging-activemq:2.0">
    <server name="default">
        <security-setting name="#">
            <role consume="true" create-non-durable-queue="true" delete-non-durable-queue="true" name="guest" send="true"/>
        </security-setting>
        <address-setting dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" message-counter-history-day-limit="10" name="#" page-size-bytes="2097152"/>
        <http-connector endpoint="http-acceptor" name="http-connector" socket-binding="http"/>
        <http-connector endpoint="http-acceptor-throughput" name="http-connector-throughput" socket-binding="http">
            <param name="batch-delay" value="50"/>
        </http-connector>
        <in-vm-connector name="in-vm" server-id="0">
            <param name="buffer-pooling" value="false"/>
        </in-vm-connector>
        <remote-connector name="netty" socket-binding="remote-messaging"/>
        <http-acceptor http-listener="default" name="http-acceptor"/>
        <http-acceptor http-listener="default" name="http-acceptor-throughput">
            <param name="batch-delay" value="50"/>
            <param name="direct-deliver" value="false"/>
        </http-acceptor>
        <in-vm-acceptor name="in-vm" server-id="0">
            <param name="buffer-pooling" value="false"/>
        </in-vm-acceptor>
        <remote-acceptor name="netty" socket-binding="messaging"/>
        <jms-queue entries="java:/jms/queue/ExpiryQueue" name="ExpiryQueue"/>
        <jms-queue entries="java:/jms/queue/DLQ" name="DLQ"/>
        <jms-queue entries="queue/clientPending" name="clientPending"/>
        <jms-queue name="AuditTrailMDB" entries="queue/AuditTrailMDB"/>
        <connection-factory connectors="in-vm" entries="java:/ConnectionFactory" name="InVmConnectionFactory"/>
        <pooled-connection-factory connectors="netty" entries="java:jboss/exported/jms/RemoteConnectionFactory" name="RemoteConnectionFactory" user="admin" password="admin"/>
        <pooled-connection-factory connectors="in-vm" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" name="activemq-ra" transaction="xa"/>
        <connection-factory connectors="in-vm" entries="/ApplicationsQueueConnectionFactory" name="ApplicationsQueueConnectionFactory"/>
    </server>
</subsystem>
...
<socket-binding name="messaging" port="5445"/>
...

log:

[WARN ][logstash.inputs.jms      ][main] JMS Consumer Died {:exception=>"Java::JavaxNaming::NameNotFoundException", :exception_message=>"queueConnectionFactory", :backtrace=>["org.apache.activemq.artemis.jndi.ReadOnlyContext.lookup(org/apache/activemq/artemis/jndi/ReadOnlyContext.java:236)", "javax.naming.InitialContext.lookup(javax/naming/InitialContext.java:417)", "java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)", "org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:455)", "org.jruby.javasupport.JavaMethod.invokeDirect(org/jruby/javasupport/JavaMethod.java:316)", "home.Alternant.logstash.vendor.bundle.jruby.$2_dot_5_dot_0.gems.jruby_minus_jms_minus_1_dot_3_dot_0_minus_java.lib.jms.connection.initialize
1

1 Answers

2
votes

There's a handful of things wrong with your configuration both for JBoss EAP and for Logstash.


Let's start with JBoss EAP...

First, you changed the default configuration of RemoteConnectionFactory to this:

<pooled-connection-factory connectors="netty" entries="java:jboss/exported/jms/RemoteConnectionFactory" name="RemoteConnectionFactory" user="admin" password="admin"/>

This is incorrect. A remote client cannot use a pooled-connection-factory, only a client in the same JVM as the application server can (e.g. an MDB which needs to send a message). You should use the default configuration instead:

<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>

Second, your AuditTrailMDB queue will not be available to remote clients. Here's its configuration:

<jms-queue name="AuditTrailMDB" entries="queue/AuditTrailMDB"/>

It needs a new JNDI entry in the java:jboss/exported/ namespace in order to be available to remote clients (e.g. like RemoteConnectionFactory has). Therefore you should use this:

<jms-queue name="AuditTrailMDB" entries="queue/AuditTrailMDB java:jboss/exported/AuditTrailMDB"/>

Now for Logstash...

First, you're using the wrong JNDI properties. The properties you're using are for the ActiveMQ Artemis JNDI implementation. Here's your current configuration:

jndi_context => { 
 'java.naming.factory.initial' => 'org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory'
 'java.naming.security.principal' => 'admin'
 'java.naming.provider.url' => 'tcp://localhost:5445?type=QUEUE_CF'
 'java.naming.security.credentials' => 'admin'
}

This is incorrect. When ActiveMQ Artemis is embedded into JBoss EAP then EAP itself handles all the JNDI lookups. Therefore you should be using this configuration instead:

jndi_context => { 
 'java.naming.factory.initial' => 'org.wildfly.naming.client.WildFlyInitialContextFactory'
 'java.naming.security.principal' => 'admin'
 'java.naming.provider.url' => 'http-remoting://127.0.0.1:8080'
 'java.naming.security.credentials' => 'admin'
}

This assumes, of course, that you've added the proper admin user to EAP.

Second, your connection factory JNDI name is incorrect. You're currently using this:

jndi_name => 'queueConnectionFactory'

You should be using this instead:

jndi_name => 'jms/RemoteConnectionFactory'

Third, the jars you're using are incorrect. Here's your current configuration:

require_jars=> ['/home/Alternant/logstash/dependencies/jboss-client.jar', 
                '/home/Alternant/logstash/dependencies/artemis-ra.jar',
                '/home/Alternant/logstash/dependencies/ironjacamar-core-impl.jar',
                '/home/Alternant/logstash/dependencies/ironjacamar-core-api.jar',
                '/home/Alternant/logstash/dependencies/ironjacamar-common-api.jar']

You don't need most of these at all. You can simplify your configuration by using the wildfly-client-all "uber" jar which is available here. Then your configuration would look like this:

require_jars=> ['/home/Alternant/logstash/dependencies/wildfly-client-all-7.1.0.GA-redhat-11.jar']