日期:2014-05-16 浏览次数:20769 次
<?xml version="1.0" encoding="GBK"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="failover:(tcp://localhost:61616)"/> <property name="transportListener"> <bean class="com.viva.server.message.jms.JmsTransportListener"/> </property> </bean> <bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="Huzl.queue"></constructor-arg> </bean> <bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic"> <constructor-arg value="Huzl.topic"></constructor-arg> </bean> <bean id="messageConvert" class="com.viva.server.message.jms.VivaMessageConvert"/> <bean id="queueTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="jmsFactory" /> <property name="defaultDestination" ref="queueDestination"/> <property name="messageConverter" ref="messageConvert"/> </bean> <bean id="topicTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="jmsFactory" /> <property name="defaultDestination" ref="topicDestination"/> <property name="messageConverter" ref="messageConvert"/> </bean> </beans>
import org.springframework.jms.support.converter.MessageConversionException; import org.springframework.jms.support.converter.MessageConverter; import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.Message; import javax.jms.Session; import java.util.Date; /** * User: bloodwolf_china * Date: 2008-6-24 * Time: 15:20:42 * Descript: */ public class VivaMessageConvert implements MessageConverter { public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { MapMessage msg = session.createMapMessage(); VivaUserRegisterMessage registerMessage = (VivaUserRegisterMessage) object; msg.setLong("RegisterTime",registerMessage.getRegisterTime().getTime()); msg.setInt("UserId",registerMessage.getUserId()); msg.setString("Tel",registerMessage.getTel()); return msg; } public Object fromMessage(Message message) throws JMSException, MessageConversionException { MapMessage msg = (MapMessage) message; VivaUserRegisterMessage registerMessage = new VivaUserRegisterMessage(); registerMessage.setRegisterTime(new Date(msg.getLong("RegisterTime"))); registerMessage.setUserId(msg.getInt("UserId")); registerMessage.setTel(msg.getString("Tel")); return registerMessage; } }