package org.sculptor.example.ejb.helloworld.milkyway.consumer; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.interceptor.Interceptors; import javax.jms.MessageListener; import org.sculptor.example.ejb.helloworld.milkyway.consumer.PlanetConsumerBeanBase; import org.sculptor.example.ejb.helloworld.milkyway.domain.Planet; import org.sculptor.framework.context.ServiceContextStoreInterceptor; import org.sculptor.framework.errorhandling.ApplicationException; import org.sculptor.framework.errorhandling.ErrorHandlingInterceptor; import org.sculptor.framework.persistence.JpaFlushEagerInterceptor; /** * EJB MessageDrivenBean implementation of PlanetConsumer. * <p> * You must define resource mapping ConnectionFactory and invalidMessageQueue, * like this in jboss.xml: * * <pre> * <message-driven> * <ejb-name>eventConsumer</ejb-name> * <resource-ref> * <res-ref-name>jms/QueueFactory</res-ref-name> * <jndi-name>ConnectionFactory</jndi-name> * </resource-ref> * <resource-ref> * <res-ref-name>jms/invalidMessageQueue</res-ref-name> * <jndi-name>queue/helloworld.invalidMessageQueue</jndi-name> * </resource-ref> * </message-driven> * </pre> */ @MessageDriven(name = "planetConsumer", messageListenerInterface = MessageListener.class, activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/addPlanet") }) @Interceptors({ ServiceContextStoreInterceptor.class, ErrorHandlingInterceptor.class, JpaFlushEagerInterceptor.class }) public class PlanetConsumerBean extends PlanetConsumerBeanBase implements MessageListener { @SuppressWarnings("unused") private static final long serialVersionUID = 1L; public PlanetConsumerBean() { } public String consume(String textMessage) throws ApplicationException { Planet newPlanet = new Planet(textMessage); newPlanet.setMessage("Hello from " + textMessage); getPlanetRepository().save(newPlanet); return null; } }