0

I have a Maven Spring 4 application that I run on a local Jetty Server at http://localhost:9292. I also have a JBoss EAP server running at http://localhost:9990, on which I created a JMS topic.

But I don't know how to access the JMS elements from my Spring application.

At the end of this post are some elements from the JBoss EAP 7 configuration file standalone.xml, (messaging part)

And here is how I tried to at least access the connection factory from my Spring application

final Properties env = new Properties();
env.put(Context.PROVIDER_URL, "remote://http://localhost:9990");

Context context = new InitialContext(env);
ConnectionFactory cf = (ConnectionFactory) context.lookup("RemoteConnectionFactory");

But I have got an error:

javax.naming.NameNotFoundException; remaining name 'RemoteConnectionFactory'

Do you know how I can use the remote JMS elements like ConnectionFactory, Topic, ...

Thanks in advance for your help

<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
    <server name="default">
        <cluster password="${jboss.messaging.cluster.password:CHANGE ME!!}"/>
        <security-setting name="#">
            <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true"/>
        </security-setting>
        <address-setting name="#" redistribution-delay="1000" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" expiry-address="jms.queue.ExpiryQueue" dead-letter-address="jms.queue.DLQ"/>
        <http-connector name="http-connector" endpoint="http-acceptor" socket-binding="http"/>
        <http-connector name="http-connector-throughput" endpoint="http-acceptor-throughput" socket-binding="http">
            <param name="batch-delay" value="50"/>
        </http-connector>
        <in-vm-connector name="in-vm" server-id="0"/>
        <http-acceptor name="http-acceptor" http-listener="default"/>
        <http-acceptor name="http-acceptor-throughput" http-listener="default">
            <param name="batch-delay" value="50"/>
            <param name="direct-deliver" value="false"/>
        </http-acceptor>
        <in-vm-acceptor name="in-vm" server-id="0"/>
        <broadcast-group name="bg-group1" connectors="http-connector" jgroups-channel="activemq-cluster"/>
        <discovery-group name="dg-group1" jgroups-channel="activemq-cluster"/>
        <cluster-connection name="my-cluster" discovery-group="dg-group1" connector-name="http-connector" address="jms"/>
        <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
        <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
        <jms-topic name="my_topic" entries="java:/jms/topic/my_topic"/>
        <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
        <connection-factory name="RemoteConnectionFactory" reconnect-attempts="-1" block-on-acknowledge="true" ha="true" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
        <pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>
    </server>
</subsystem>

Socket-binding part:

<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
    <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}"/>
    <socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
    <socket-binding name="http" port="${jboss.http.port:8080}"/>
    <socket-binding name="https" port="${jboss.https.port:8443}"/>
    <socket-binding name="iiop" interface="unsecure" port="3528"/>
    <socket-binding name="iiop-ssl" interface="unsecure" port="3529"/>
    <socket-binding name="jgroups-mping" interface="private" port="0" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45700"/>
    <socket-binding name="jgroups-tcp" interface="private" port="7600"/>
    <socket-binding name="jgroups-tcp-fd" interface="private" port="57600"/>
    <socket-binding name="jgroups-udp" interface="private" port="55200" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45688"/>
    <socket-binding name="jgroups-udp-fd" interface="private" port="54200"/>
    <socket-binding name="modcluster" port="0" multicast-address="224.0.1.105" multicast-port="23364"/>
    <socket-binding name="txn-recovery-environment" port="4712"/>
    <socket-binding name="txn-status-manager" port="4713"/>
    <outbound-socket-binding name="mail-smtp">
        <remote-destination host="localhost" port="25"/>
    </outbound-socket-binding>
</socket-binding-group>
Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
Kris
  • 401
  • 2
  • 7
  • 16

1 Answers1

1

I see a few things wrong:

  • I would recommend specifying the initial context factory, e.g.:

    env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
    
  • Your JNDI lookup should use http-remoting://localhost:8080 by default.

  • Remote clients lookup JNDI entries based on what comes after java:jboss/exported/ in the server-side configuration. In the case of your RemoteConnectionFactory connection factory you should use jms/RemoteConnectionFactory in your lookup, e.g.:

    ConnectionFactory cf = (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
    
  • If you want to lookup the my_topic topic from a remote client you'll need to add an entry which exposes the JNDI name remotely, e.g.:

    <jms-topic name="my_topic" entries="java:/jms/topic/my_topic java:jboss/exported/jms/topic/my_topic"/>
    
Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • Thanks for your answer. For now I have an error at my first lookup: javax.naming.NamingException: Failed to connect to any server. Servers tried: [remote://localhost:4447], after having added initial context factory as you mentionned. I also tried with remote://localhost:8080 but same result. So I'm still searching – Kris Jan 17 '19 at 09:34
  • Is the server running? Are you running the client on the same machine as the server? Is the server configured to use the default port for JNDI (i.e. 4447)? – Justin Bertram Jan 17 '19 at 13:43
  • Yes. Both are running on the same machine. In the standalone.xml file I didn't see any 4447 number. But I saw so I tried also with port 8080. – Kris Jan 17 '19 at 14:02
  • A colleague suggested to add env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "true"); env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); – Kris Jan 17 '19 at 14:02
  • Please paste your server configuration into the original question. – Justin Bertram Jan 17 '19 at 14:04
  • The file standalone.xml is quite big. Do you think there is something specific I should paste? Anyway I updated my post to make it include the whole messaging configuration and socket-binding parts – Kris Jan 17 '19 at 14:13
  • Can you confirm you're running JBoss AS7? By default there is a `remoting` socket-binding which uses port 4447. This is the default port for JNDI. It appears you're either not use JBoss AS7 or you've changed the default configuration. – Justin Bertram Jan 17 '19 at 14:48
  • Yes it is JBoss EAP 7.0.0. Maybe the remoting socket-binding (with port 4447) came in a later version (7.1 ?). The JBoss 7 instance was provided by a person in charge of its mainteance in the company, as a tool for our development tests. But he is in holidays at the moment. :) I'll ask if I can have a later version of the JBoss instance. Thanks again for your help. – Kris Jan 18 '19 at 09:47
  • When your question said "JBOSS 7" I assumed you meant JBoss AS7 and not JBoss EAP 7. Those are *different* versions; AS7 is a community version and EAP 7 is the commercially supported version from Red Hat (which is based on the community version but the versions don't necessarily align). I've updated my answer accordingly. – Justin Bertram Jan 18 '19 at 14:25