NutzCN Logo
问答 大神,麻烦问下activemq的这个配置文件的这段代码在nutz的js配置文件中怎么表现,我试了好多种情况都不管用
发布于 1467天前 作者 liuwq001111 1089 次浏览 复制 上一个帖子 下一个帖子
标签:
<bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic">
    <constructor-arg value="${activemq.bz.topic}" index="0" />
</bean>

请问大神,上面这段配置文件在nutz的js文件中怎么表现?下面是我试的接种情况:
1.
topicDestination : {
type : "org.apache.activemq.command.ActiveMQTopic",
args : [
{value:"BZ.Topic.HB"},
{index:"0"}
]
// args : [
// {java:"$conf.get('activemq.topic')"}
// ]
},

2.
topicDestination : {
type : "org.apache.activemq.command.ActiveMQTopic",
// args : [
// {value:"BZ.Topic.HB"},
// {index:"0"}
// ]
args : [
{java:"$conf.get('activemq.topic')"}
]
},

3.
topicDestination : {
type : "org.apache.activemq.command.ActiveMQTopic",
// args : [
// {value:"BZ.Topic.HB"},
// {index:"0"}
// ]
// args : [
// {java:"$conf.get('activemq.topic')"}
// ]
args : ["BZ.Topic.HB"]
},

求大神指点!!!

5 回复

第二种应该就是对的

那您能帮我看下这个整体的配置文件有问题吗?我感觉没问题,可是就是监听不到消息
var activemq = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["custom/activemq.properties"]
}
},
targetConnectionFactory : {
type : "org.apache.activemq.ActiveMQConnectionFactory",
fields : {
brokerURL : {java:"$conf.get('activemq.url')"},
userName : {java:"$conf.get('activemq.userName')"},
password : {java:"$conf.get('activemq.password')"},
useAsyncSend : "true",
redeliveryPolicy : {
defaultRedeliveryPolicy : {
type : "org.apache.activemq.RedeliveryPolicy",
fields : {
maximumRedeliveries : {java:"10"},
redeliveryDelay : {java:"6000"},
}
}
}
}
},

connectionFactory : {
    type : "org.springframework.jms.connection.CachingConnectionFactory",
    fields : {
        targetConnectionFactory : {refer : 'targetConnectionFactory'},
        reconnectOnException : "true",
        cacheConsumers : "false",
        cacheProducers : "false",
        sessionCacheSize : 50,
        clientId : "clientId_jgzf",
    }
},

consumerSessionAwareMessageListener : {
    type : "com.axgt.safety.context.mq.ConsumerSessionAwareMessageListener",
},

backOff : {
    type : "org.springframework.util.backoff.ExponentialBackOff",
},

topicDestination : {
    type : "org.apache.activemq.command.ActiveMQTopic",
     args : [
             {java:"$conf.get('activemq.topic')"}
         ]
},

//消费者

jmsContainer : {
    type : "org.springframework.jms.listener.DefaultMessageListenerContainer",
    fields : {
        connectionFactory : {refer : 'connectionFactory'},
        // destination : {refer : 'topicDestination'},
        messageListener : {refer : 'consumerSessionAwareMessageListener'},
        backOff : {refer : 'backOff'},
        autoStartup : {java:"$conf.get('activemq.turnOn')"},
        subscriptionDurable : "true",
        pubSubDomain : "true",
        clientId : "clientId_jgzf",
        durableSubscriptionName : "clientId_jgzf"
    }
},

};

activemq.url=tcp://10.114.12.63:61616
activemq.queue=zhpt.queue
activemq.userName=system
activemq.password=manager
activemq.topic=BZ.Topic.HB
activemq.turnOn=true
spring.jms.listener.acknowledge-mode=CLIENT

参考下面这段修改的,有没有语法不对的或者嵌套错误的情况?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.springframework.org/schema/jms"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd">

    <bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="${activemq.url}"/>
        <property name="userName" value="${activemq.userName}"/> <!-- 连接的用户名 -->
        <property name="password" value="${activemq.password}"/> <!-- 连接的密码 -->
        <property name="useAsyncSend" value="true"/>
        <property name="redeliveryPolicy">
               <bean name="defaultRedeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
                  <property name="maximumRedeliveries" value="10"/>
                     <property name="redeliveryDelay" value="60000"/>
             </bean>
       </property>
    </bean>
    <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
        <!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory -->
        <property name="targetConnectionFactory" ref="targetConnectionFactory"/>
        <property name="reconnectOnException" value="true"/>
        <property name="cacheConsumers" value="false"/>
        <property name="cacheProducers" value="false"/>
        <property name="sessionCacheSize" value="50"/>
        <property name="clientId" value="clientId_jgzf"/>
    </bean>
    

    <!-- 消息监听类(实现类),订阅模式 -->
    <bean id="bzkListener" class="com.safety.app.mq.BzkListener"></bean>

    <bean id="backOff" class="org.springframework.util.backoff.ExponentialBackOff"></bean>

    <!-- 这个是队列目的地 -->
    <bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic">
        <constructor-arg value="${activemq.bz.topic}" index="0" />
    </bean>

    <!-- 消息监听容器 -->
    <bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="destination" ref="topicDestination"/>
        <property name="messageListener" ref="bzkListener"/>
        <property name="backOff" ref="backOff"/>
        <property name="autoStartup" value="${activemq.turnOn}"/>
        <!-- <property name="clientId" value="clientId_zhpt"/> -->
        <property name="subscriptionDurable" value="true"/>
        <property name="pubSubDomain" value="true"/>
        <property name="clientId" value="clientId_jgzf"/>
        <property name="durableSubscriptionName" value="clientId_jgzf"/>
    </bean>

    <!-- 定义Queue监听器,点对点消息模式 -->
    <!--<jms:listener-container destination-type="queue" container-type="default"  connection-factory="connectionFactory">-->
        <!--<jms:listener destination="${activemq.queue}" ref="queueReceiver"/>-->
    <!--</jms:listener-container>-->

</beans>
var activemq = {
    conf : {
        type : "org.nutz.ioc.impl.PropertiesProxy",
        fields : {
            paths : ["custom/activemq.properties"]
        }
    },
    targetConnectionFactory : {
        type : "org.apache.activemq.ActiveMQConnectionFactory",
        fields : {
            brokerURL : {java:"$conf.get('activemq.url')"},
            userName : {java:"$conf.get('activemq.userName')"},
            password : {java:"$conf.get('activemq.password')"},
            useAsyncSend : "true",
            redeliveryPolicy : {
                defaultRedeliveryPolicy : {
                    type : "org.apache.activemq.RedeliveryPolicy",
                    fields : {
                        maximumRedeliveries : {java:"10"},
                        redeliveryDelay : {java:"6000"},
                    }
                }
            }
        }
    },

    connectionFactory : {
        type : "org.springframework.jms.connection.CachingConnectionFactory",
        fields : {
            targetConnectionFactory : {refer : 'targetConnectionFactory'},
            reconnectOnException : "true",
            cacheConsumers : "false",
            cacheProducers : "false",
            sessionCacheSize : 50,
            clientId : "clientId_jgzf",
        }
    },

    consumerSessionAwareMessageListener : {
        type : "com.axgt.safety.context.mq.ConsumerSessionAwareMessageListener",
    },

    backOff : {
        type : "org.springframework.util.backoff.ExponentialBackOff",
    },

    topicDestination : {
        type : "org.apache.activemq.command.ActiveMQTopic",
        // args : [
        //            {value:"BZ.Topic.HB"},
        //            {index:"0"}
        //        ]
        // args : [
        //         {java:"$conf.get('activemq.topic')"}
        //     ]
        args : ["BZ.Topic.HB"]
    },

    // destinationOne : {
    //     type : "org.apache.activemq.command.ActiveMQQueue",
    //     args : [
    //             {java:"$conf.get('activemq.queue')"}
    //         ]
    // },

    // jmsTemplateOne : {
    //     type : "org.springframework.jms.core.JmsTemplate",
    //     fields : {
    //         connectionFactory : {refer : 'connectionFactory'},
    //         defaultDestination : {refer : 'destinationOne'},
    //         receiveTimeout : "6000"
    //     }
    // },
    //
    // //生产者
    // senderService : {
    //     type : "com.axgt.safety.module.activemq.SenderService",
    //     fields : {
    //         jmsTemplateOne : {refer : 'jmsTemplateOne'},
    //     }
    // },

    //消费者

    jmsContainer : {
        type : "org.springframework.jms.listener.DefaultMessageListenerContainer",
        fields : {
            connectionFactory : {refer : 'connectionFactory'},
            // destination : {refer : 'topicDestination'},
            messageListener : {refer : 'consumerSessionAwareMessageListener'},
            backOff : {refer : 'backOff'},
            autoStartup : {java:"$conf.get('activemq.turnOn')"},
            subscriptionDurable : "true",
            pubSubDomain : "true",
            clientId : "clientId_jgzf",
            durableSubscriptionName : "clientId_jgzf"
        }
    },
};

nutz ioc是懒加载的

你得在Setup.init里面获取一下这些bean,才会初始化

添加回复
请先登陆
回到顶部