Skip to content

Commit 5bb2f77

Browse files
johnamentbartoszmajsak
authored andcommitted
#254 Added examples w/ new JMS APIs
1 parent 6f76eb5 commit 5bb2f77

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

jms/jms-xa/src/main/java/org/javaee7/jms/xa/JMSMailman.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import javax.jms.JMSException;
77
import javax.jms.Message;
88
import javax.jms.MessageListener;
9-
import javax.jms.TextMessage;
109
import java.util.logging.Level;
1110
import java.util.logging.Logger;
1211

@@ -24,8 +23,8 @@ public class JMSMailman implements MessageListener {
2423
public void onMessage(Message message)
2524
{
2625
try {
27-
TextMessage tm = (TextMessage) message;
28-
logger.info("Message received (async): " + tm.getText());
26+
String text = message.getBody(String.class);
27+
logger.info("Message received (async): " + text);
2928
deliveryStats.messageDelivered();
3029
} catch (JMSException ex) {
3130
logger.log(Level.SEVERE, null, ex);

jms/jms-xa/src/main/java/org/javaee7/jms/xa/Mailman.java

+3-23
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
import javax.annotation.Resource;
44
import javax.ejb.Singleton;
55
import javax.inject.Inject;
6-
import javax.jms.Connection;
76
import javax.jms.ConnectionFactory;
7+
import javax.jms.JMSContext;
88
import javax.jms.JMSDestinationDefinition;
9-
import javax.jms.JMSException;
10-
import javax.jms.MessageProducer;
119
import javax.jms.Queue;
12-
import javax.jms.Session;
13-
import javax.jms.TextMessage;
1410

1511
@JMSDestinationDefinition(
1612
name = Mailman.CLASSIC_QUEUE,
@@ -32,24 +28,8 @@ public class Mailman {
3228

3329
public void sendMessage(String payload)
3430
{
35-
Connection connection = null;
36-
try {
37-
connection = connectionFactory.createConnection();
38-
connection.start();
39-
Session session = connection.createSession(false, Session.SESSION_TRANSACTED);
40-
MessageProducer messageProducer = session.createProducer(demoQueue);
41-
TextMessage textMessage = session.createTextMessage(payload);
42-
messageProducer.send(textMessage);
43-
} catch (JMSException ex) {
44-
ex.printStackTrace();
45-
} finally {
46-
if (connection != null) {
47-
try {
48-
connection.close();
49-
} catch (JMSException ex) {
50-
ex.printStackTrace();
51-
}
52-
}
31+
try (JMSContext context = connectionFactory.createContext()) {
32+
context.createProducer().send(demoQueue,payload);
5333
}
5434
}
5535
}

jms/jms-xa/src/test/resources/arquillian.xml

+6
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@
88
<property name="deploymentExportPath">target/deployment</property>
99
</engine>
1010

11+
<container qualifier="wildfly">
12+
<configuration>
13+
<property name="serverConfig">standalone-full.xml</property>
14+
</configuration>
15+
</container>
16+
1117
</arquillian>

pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@
465465
<configuration>
466466
<systemPropertyVariables>
467467
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
468+
<arquillian.launch>wildfly</arquillian.launch>
468469
</systemPropertyVariables>
469470
<environmentVariables>
470471
<JBOSS_HOME>${project.build.directory}/wildfly-${org.wildfly}</JBOSS_HOME>
@@ -559,6 +560,9 @@
559560
<environmentVariables>
560561
<JBOSS_HOME>${project.build.directory}/wildfly-${org.wildfly}</JBOSS_HOME>
561562
</environmentVariables>
563+
<systemPropertyVariables>
564+
<arquillian.launch>wildfly</arquillian.launch>
565+
</systemPropertyVariables>
562566
</configuration>
563567
</plugin>
564568
</plugins>

0 commit comments

Comments
 (0)