메시지 받기 (onMessage)
package org.jtop.spirng.sample.activemq.receive;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* @author lee
*/
public class Receiver implements MessageListener {
Log log = LogFactory.getLog(this.getClass());
public void onMessage(Message message) {
try {
TextMessage tm = (TextMessage)message;
log.debug("Property : " + tm.getStringProperty("Property"));
log.debug("Text : " + tm.getText());
} catch (JMSException e) {
log.error("onMessage Exception : ", e);
}
}
}
실행하는 클래스
package org.jtop.spirng.sample.activemq.receive;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Runner{
Log log = LogFactory.getLog(this.getClass());
private void run() {
ApplicationContext ctx = new FileSystemXmlApplicationContext("conf/activemq/activemq_receive.xml");
ctx.getBean("start");
log.info("============= onMeesage() ==============");
}
public static void main(String[] args) {
Runner job = new Runner();
job.run();
}
}
activemq_receive.xml 내용
<?xml version="1.0" encoding="euc-kr"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- === XML이 로딩되면서 자동으로 messageListener 동작(start는 단순 로딩용) === -->
<bean id="start" class="java.lang.String"/>
<bean id="r_connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="r_jndiTemplate"/>
</property>
<property name="jndiName">
<value>ConnectionFactory</value>
</property>
</bean>
<bean id="r_jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">
org.apache.activemq.jndi.ActiveMQInitialContextFactory
</prop>
<prop key="java.naming.provider.url">
tcp://localhost:61616
</prop>
</props>
</property>
</bean>
<bean id="r_destination" class="org.apache.activemq.command.ActiveMQTopic" autowire="constructor">
<constructor-arg value="FOO.BAR" />
</bean>
<bean id="messageListener" class="org.jtop.spirng.sample.activemq.receive.Receiver" />
<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="r_connectionFactory" />
<property name="destination" ref="r_destination" />
<property name="messageListener" ref="messageListener" />
</bean>
</beans>
카테고리
태그목록
최근에 올라온 글
최근에 달린 댓글
최근에 받은 트랙백
달력
글 보관함
링크
Total :
Today : Yesterday :
Today : Yesterday :