/[projects]/miscJava/Test3/src/dk/thoerup/messagedriven/MDBean.java
ViewVC logotype

Annotation of /miscJava/Test3/src/dk/thoerup/messagedriven/MDBean.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1271 - (hide annotations) (download)
Wed Apr 6 21:41:41 2011 UTC (13 years, 2 months ago) by torben
File size: 1063 byte(s)
Add messagedriven bean example
1 torben 1271 package dk.thoerup.messagedriven;
2    
3     import javax.ejb.ActivationConfigProperty;
4     import javax.ejb.MessageDriven;
5     import javax.jms.JMSException;
6     import javax.jms.Message;
7     import javax.jms.MessageListener;
8     import javax.jms.TextMessage;
9    
10    
11     //destination must be created on server before deployment
12     //GFv3 -> resourcces -> JMS resources -> destination resources -> new
13     @MessageDriven(mappedName = "jms/hello", activationConfig = {
14     @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
15     @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
16     })
17    
18    
19     public class MDBean implements MessageListener {
20    
21     @Override
22     public void onMessage(Message message) {
23    
24     try {
25     System.out.println("onMessage: " + message.getStringProperty("name") );
26    
27     if (message instanceof TextMessage) {
28     TextMessage txt = (TextMessage) message;
29     System.out.println("Body" + txt.getText() );
30     }
31    
32     } catch (JMSException e) {
33     System.out.println( e.getMessage() );
34     }
35    
36     }
37     }

  ViewVC Help
Powered by ViewVC 1.1.20