0
votes

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>
1

1 Answers

1
votes

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"/>