1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.xa;
18
19 import javax.ejb.ActivationConfigProperty;
20 import javax.ejb.MessageDriven;
21 import javax.inject.Inject;
22 import javax.jms.JMSException;
23 import javax.jms.Message;
24 import javax.jms.MessageListener;
25 import javax.jms.TextMessage;
26 import java.util.logging.Logger;
27
28
29
30
31
32
33
34
35
36
37
38
39 @MessageDriven(name = "DbUpdaterMDB", activationConfig = {
40 @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
41 @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/jta-crash-rec-quickstart"),
42 @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
43 public class DbUpdaterMDB implements MessageListener {
44
45 private final static Logger LOGGER = Logger.getLogger(DbUpdaterMDB.class.getName());
46
47
48 @Inject
49 private XAService xaService;
50
51 public void onMessage(Message rcvMessage) {
52 LOGGER.info("Received Message: " + rcvMessage.toString());
53
54 try {
55 if (rcvMessage instanceof TextMessage) {
56 TextMessage msg = (TextMessage) rcvMessage;
57 String sm = msg.getText();
58 String[] kvPair = sm.split("=");
59
60
61 if (kvPair.length == 2 && kvPair[0].length() != 0) {
62 xaService.modifyKeyValueTable(false, kvPair[0], kvPair[1] + " updated via JMS");
63 LOGGER.info("JTA Crash Record Quickstart: key value pair updated via JMS");
64 }
65 } else {
66 LOGGER.warning("JTA Crash Record Quickstart: Unexpected message. Type: " + rcvMessage.getClass().getName());
67 }
68 } catch (JMSException e) {
69 throw new RuntimeException(e);
70 }
71 }
72 }