메시지 받기 (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>
Posted by 아름프로
BLOG main image

카테고리

분류 전체보기 (539)
이야기방 (19)
토론/정보/사설 (16)
IBM Rational (9)
U-IT (0)
SOA/WS/ebXML (110)
개발방법론/모델링 (122)
J2SE (34)
J2EE (60)
DataBase (39)
Open Projects (30)
BP/표준화 (50)
Apache Projects (15)
Web/보안/OS (22)
Tools (7)
AJAX/WEB2.0 (1)
Linux/Unix (1)
영어 (0)
비공개방 (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

달력

«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

글 보관함

Total :
Today : Yesterday :