1 |
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 |
} |