解决方案 »
- 线程安全必须要通过synchronized实现吗?
- hashMap的反序列化问题
- 对Null和""的疑惑?
- 问:一个方法给定两个日期,怎么求出相距天数啊
- PreparedStatement对象创建时,具体的实现过程是由JDBC实现,还是由具体的数据库实现
- 问个方法的用法,请不吝指教,谢谢!
- 数据库中存取datetime型字段怎么实现 !!!!急急急急急急!!!!!!
- jbuilder7中一个简单的问题
- 急,用jdbc-odbc连接access数据库,是否支持cursor的上下游动?(在线等待)
- Struts2中典型CRUD Action的抽象基类 怎么跳页面的??
- 关于向表中插数据的问题
- 本人菜鸟刚学习hibernate 在练习对数据添加数据时遇到问题实在解决不了求高手帮忙
public void convertAndSend(Event message) {
// build ConnectionFactory And Queue is necessary
buildConnectionFactoryAndQueue();
Connection connect = null;
Session session = null;
MessageProducer producer = null;
try {
connect = jmsConnectionFactory.createConnection();
session = connect.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
producer = session.createProducer(queue);
// create a JMS message and send it
ObjectMessage objMsg = session.createObjectMessage(message);
// set message selector
String messageSelector = message.getMessageSelector();
objMsg.setStringProperty("messageReceiver", messageSelector); producer.send(objMsg);
} catch (JMSException e) {
String errorMessage = "JMSException while queueing HTTP JMS Message";
throw new EventRuntimeException(errorMessage, e);
} finally {
SafeCloseUtil.close(producer); // 这里关闭 producer
SafeCloseUtil.close(session); // 这里关闭 producer
SafeCloseUtil.close(connect);
}
}
服务端只需要实现MessageListener的onMessage,客户端的 session服务端根本不知道,也无法关闭。
@Override
public void onMessage(Message message) {
printLogMessage("start public function onMessage()..");
try {
if (message instanceof ObjectMessage) {
ObjectMessage objMsg = (ObjectMessage) message;
Event event = (Event) objMsg.getObject();
// if Re deliver message warn the message
if (message.getJMSRedelivered()) {
log.warn("...", event.getClass().getSimpleName());
}
// out Put Event Log
outPutEventLog(event);
// dispatch Event
dispatchEvent(event);
} else {
log.error("This MDB message was not instance of ObjectMessage; ignoring.");
} printLogMessage("end public function onMessage()..");
} catch (JMSException e) {
String errorMessage = "JMS Exception while Listener message.errorMessage:"
+ e.getMessage();
log.error(errorMessage);
throw new EventRuntimeException(errorMessage, e);
}
}
首先,你说的服务端和客户端,
因为你说服务端实现onMessage接口,
所以我是不是可以理解为
你说的服务端算是消息的接收端,
而客户端是消息的发送端那么,
也就是说,
一旦消息接收端的程序开始运行,开始接收消息,
就始终要开着这个链接,准备消息发送端随时发来的消息?但是,我这个工程里,
消息接收端是一个任务(task)对象,
一段时间内只处理一部分发送过来的消息。
(接收固定数量的消息的方法我在ActiveMQ自带的例子里看到过,方法也了解)
按照上面我"一旦"的逻辑,
是不是这个任务在第一次执行的时候就一直执行下去了?
而不会真正的推出,
而受限于jdk的timer的运行机制,(第一个task运行完了,才安排第2个task运行)
这个任务(task)就是不是始终不会被第二次执行了?比如:
这个任务在第一次被执行的时候,
取得一个consumer->设定了onMessage->被触发后,
这个任务就一直等待发送端发送过来的消息,
而因为它始终是处于活态(忘了什么词了,反正就是一直存在的意思)
timer就不会安排第2次,第3次启动?那么我这个task就没有意义了。
我是不是要考虑其他的方式了呢?
或者直接干脆就执行这个任务一次(直接执行run方法,代码也不改了)??...
还是说当发送端关闭了这个session,
接收端的各种资源也就释放了?
(应该不会这样吧?
因为发送端和接收端都隔着一个ActiveMQ,
难道ActiveMQ会通知他的其他弟兄关闭关于自己的接收?)一大嘟噜问题,真是不好意思
有空给在下点拨点拨呗
谢谢了good luck
<bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL"
value="failover:(tcp://10.60.60.107:61616?wireFormat.maxInactivityDuration=0)&maxReconnectDelay=1000" />
</bean>
</property>
<!-- 连接数 -->
<property name="maxConnections" value="1" />
<!-- Session总数 -->
<property name="maximumActive" value="500" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<!--
<property name="defaultDestination" ref="oamTmpTopic" />
-->
<property name="explicitQosEnabled" value="true" />
<!-- 1为非持久化,2为持久化 -->
<property name="deliveryMode" value="1" />
</bean>