远程服务器上的Spring Access JMS

时间:2019-01-14 13:24:40

标签: jms spring-jms jboss-eap-7

我有一个在http://localhost:9292的本地Jetty服务器上运行的Maven Spring 4应用程序。 我也有一个运行在http://localhost:9990上的JBoss EAP服务器,在上面创建了一个JMS主题。

但是我不知道如何从我的Spring应用程序访问JMS元素。

本文最后是JBoss EAP 7配置文件standalone.xml中的一些元素(消息部分)

这是我尝试至少从我的Spring应用程序访问连接工厂的方式

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");

但是我有一个错误:

  

javax.naming.NameNotFoundException;剩余的名字   'RemoteConnectionFactory'

您知道我如何使用远程JMS元素,例如ConnectionFactory,Topic,...

预先感谢您的帮助

<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-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 个答案:

答案 0 :(得分:0)

我发现一些错误:

  • 我建议指定初始上下文工厂,例如:

    env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
    
  • 默认情况下,您的JNDI查找应使用http-remoting://localhost:8080

  • 远程客户端根据服务器端配置中java:jboss/exported/之后的内容查找JNDI条目。对于RemoteConnectionFactory连接工厂,您应该在查询中使用jms/RemoteConnectionFactory,例如:

    ConnectionFactory cf = (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
    
  • 如果要从远程客户端查找my_topic主题,则需要添加一个条目以远程公开JNDI名称,例如:

    <jms-topic name="my_topic" entries="java:/jms/topic/my_topic java:jboss/exported/jms/topic/my_topic"/>