为 Jboss_EAP_7.0 上的 jms 主题配置持久订阅者

Configuring durable subscriber for jms topic on Jboss_EAP_7.0

在 Jboss_EAP_7.0 上为 jms 主题配置持久订阅者时,它是否需要任何配置,例如独立的客户端 ID -full.xml 还是我应该在我的侦听器中初始化客户端 ID

这是我的独立-full.xml jms

配置
 <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
            <server name="default" persistence-enabled="false">
                <security-setting name="#">
                    <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true" create-durable-queue="true"/>
                </security-setting>
                <address-setting name="jms.queue.FromExchange" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" max-delivery-attempts="3" redelivery-multiplier="2.0" redelivery-delay="6000" 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"/>
                <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
                <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
                <jms-queue name="ToExchange" durable="false" entries="java:/jms/queue/ToExchange java:jboss/exported/jms/queue/ToExchange"/>
                <jms-queue name="FromExchange" durable="false" entries="java:/jms/queue/FromExchange java:jboss/exported/jms/queue/FromExchange"/>
                <jms-topic name="ORD_CLINT_PUSH" entries="java:/jms/topic/ORD_CLINT_PUSH java:/jboss/exported/jms/topic/ORD_CLINT_PUSH"/>
                <jms-topic name="ORD_CLINT" entries="java:/jms/topic/ORD_CLINT java:/jboss/exported/jms/topic/ORD_CLINT"/>
                <connection-factory name="InVmConnectionFactory" thread-pool-max-size="100" entries="java:/ConnectionFactory" connectors="in-vm"/>
                <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
                <connection-factory name="RemoteConnectionFactorySTP" thread-pool-max-size="10" failover-on-initial-connection="true" reconnect-attempts="-1" block-on-acknowledge="true" client-failure-check-period="10000" ha="true" entries="java:jboss/exported/jms/RemoteConnectionFactorySTP" connectors="http-connector"/>
                <pooled-connection-factory name="activemq-ra" max-pool-size="50" min-pool-size="20" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>
            </server>
        </subsystem>

下面是我的 initializeConnection 方法,我在其中定义了客户端 ID。这是否正确或需要任何更改

 public void initializeConnection() {
        reconnectAttempts++;
        System.out.println("connecting.....");

        Hashtable props = new Hashtable();
        props.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
        props.put(Context.PROVIDER_URL, providerURL);
        props.put("java.naming.rmi.security.manager", "yes");
        props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
        if ((userName != null) && (password != null)) {
            props.put(Context.SECURITY_PRINCIPAL, userName);
            props.put(Context.SECURITY_CREDENTIALS, password);
        }

        try {
            Context context = new InitialContext(props);
            topicConnectionFactory = (TopicConnectionFactory) context.lookup(connectionFactory);
            inputTopic = (Topic) context.lookup(queueName);
            context.close();

            if ((userName != null) && (password != null)) {
                topicConnection = topicConnectionFactory.createTopicConnection(userName, password);   //send username and password for EAP
            } else {
                topicConnection = topicConnectionFactory.createTopicConnection();
            }
            topicConnection.setClientID("Durable_S_1");
            topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            topicReceiver = topicSession.createDurableSubscriber(inputTopic,"Durable_S_1");
           // topicReceiver = topicSession.createSubscriber(inputTopic);
            topicConnection.setExceptionListener(new EL(this));
            topicConnection.start();

            isConnected = true;
            reconnectAttempts = 0;
            System.out.println("completed.......");
        } catch (Exception e) {
            e.printStackTrace();
            closeQueueManager();
            if (reconnectAttempts < 10) {

            } else if ((10 <= reconnectAttempts) && (reconnectAttempts < 20)) {

            } else {

            }
        }
    }

您需要将权限 create-durable-queue 添加到 true in standalone-full.xml 以创建持久订阅者。

<security-setting name="#">
   <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" create-durable-queue="true" consume="true" send="true"/>
</security-setting>