메시지 구동 Bean 개발
Enterprise JavaBeans 스펙에 도입된 것처럼 메시지 구동 Bean의 Bean 구현 클래스를 개발할 수 있습니다. MDB(메시지 구동 Bean)는 비즈니스 로직을 구현하여 서버에서 실행하는 메시지 이용자입니다.
시작하기 전에
이 태스크 정보
다음 예는 기본 메시지 구동 Bean입니다.
@MessageDriven(activationConfig={
@ActivationConfigProperty(propertyName="destination", propertyValue="myDestination"),
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue")
})
public class MsgBean implements javax.jms.MessageListener {
public void onMessage(javax.jms.Message msg) {
String receivedMsg = ((TextMessage) msg).getText();
System.out.println("Received message: " + receivedMsg);
}
}
다른 엔터프라이즈 Bean 유형의 경우와 같이 어노테이션을
사용하지 않고 배치 디스크립터에서 메시지 구동 Bean의 메타데이터를
선언할 수도 있습니다. 예를 들면, 다음과 같습니다.
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="EJBJar_1060639024453" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
metadata-complete="false">
<enterprise-beans>
<message-driven>
<ejb-name>MsgBean</ejb-name>
<ejb-class>com.acme.ejb.MsgBean</ejb-class>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>myDestination</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</ejb-jar>
참고: WebSphere® Application Server 버전 9에서,
destination 활성화 구성 특성 대신
destinationLookup 특성도 사용할 수
있습니다. 두 활성화 구성 특성은 모두
MDB를 위한 대상 JNDI 이름을 설정하는 동일한 목적을
서비스합니다. 대신, 두 활성화 특성이 모두 구성에서 정의될 때
destinationLookup 특성이
destination 특성보다 우선합니다.