我正在开发一个由J2EE和Spring组成的后端应用程序和一个前端的applet。
在一些用户操作之后,后端在activeMQ主题上发送消息以通知前端更新IHM。
我遇到一个调用ActiveMQ Broker来发送消息的问题,但是前端没有收到所有消息,有时候不会调用onMessage()
的{{1}}方法。前面接收一些消息但不是全部,来自同一主题的相同类型。它是随机行为。
我的配置如下: activemq.xml中
MessageListener
经纪人-config.xml中
<amq:broker useJmx="false" persistent="false">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://0.0.0.0:18135" />
</amq:transportConnectors>
</amq:broker>
生产者-config.xml中
<beans>
<bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
<property name="config">
<!-- ENV-ACTIVEMQ_XML -->
<value>WEB-INF/config/jms/activemq.xml</value>
</property>
</bean>
</beans>
在客户端站点中,连接设置为:
<beans>
<!-- JMS ConnectionFactory to use -->
<bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>vm://localhost</value>
</property>
</bean>
<!-- Spring JMS Template -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<!-- lets wrap in a pool to avoid creating a connection per send -->
<bean class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory">
<ref local="jmsFactory" />
</property>
</bean>
</property>
<!-- true for TOPIC mode, false for QUEUE mode -->
<property name="pubSubDomain">
<value>true</value>
</property>
</bean>
<!-- a sample POJO which uses a Spring JmsTemplate -->
<bean id="producer" class="com.airfrance.rushtbeweb.applicationlayer.broker.AlertProducer">
<property name="template">
<ref bean="jmsTemplate"></ref>
</property>
<property name="subject">
<value>ALERTES</value>
</property>
</bean>
我尝试使用KahaDB保持消息持久性,并将hostName = (String) Applet.getCtx().getAttribute(Constants.SERVER_HOSTNAME);
//serverPort = (String) Applet.getCtx().getAttribute(Constants.SERVER_PORT);
serverPort = "18135";
if (log.isInfoEnabled()){
log.info("hostName :"+ hostName );
log.info("serverPort :"+ serverPort );}
if (StringUtils.isNotEmpty(hostName)&& StringUtils.isNotEmpty(serverPort)) {
connectionFactory = new ActiveMQConnectionFactory("tcp://"+ hostName + ":" + serverPort);
if (log.isInfoEnabled()){
log.info("connectionFactory: "+ connectionFactory);}
connection = (TopicConnection) connectionFactory.createConnection();
if (log.isInfoEnabled()){
log.info("connection : "+ connection ); }
connection.setClientID(myId);
createConsumer(connection);
connection.start();
// Permet une reconnexion du client avec une phase
// d'initialisation en cas de problème de connexion.
connection.setExceptionListener(new AbstractJMSExceptionListener(connectionFactory, connection) {
public void reinitialize() throws JMSException {
createConsumer(getExListenerConnection());
}
});
while (isRunning) {
Thread.sleep(5000);
}......
private void createConsumer(TopicConnection topicConnection)
throws JMSException {
if (log.isInfoEnabled()){
log.info("STEP createConsumer");}
// securise la reception de l'alerte
// Vis a vis du broker le message est acquitté seulement si on passe
// sur la methode acknowledge()
TopicSession session = topicConnection.createTopicSession(false,Session.CLIENT_ACKNOWLEDGE);
Topic topic = session.createTopic(SUBJECT);
TopicSubscriber subscriber = session.createSubscriber(topic);
subscriber.setMessageListener(this);
}
更改为createSubscriber
,但没有结果。