blob: 2bdfcba14fd889ddffd13dd732105371e7bdedd4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package examples.messaging;
import javax.jms.*;
import javax.ejb.*;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
@MessageDriven(activationConfig =
{ @ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Topic") })
public class PoisonBean implements MessageListener {
@Resource
private MessageDrivenContext ctx;
public PoisonBean() {
System.out.println("PoisonBean created");
}
public void onMessage(Message msg) {
try {
System.out.println("Received msg " + msg.getJMSMessageID());
// Let�s sleep a little bit so that we don�t
// see rapid fire re-sends of the message.
Thread.sleep(3000);
// We could either throw a system exception here or
// manually force a rollback of the transaction.
ctx.setRollbackOnly();
} catch (Exception e) {
e.printStackTrace();
}
}
@PreDestroy
public void remove() {
System.out.println("PoisonBean destroyed.");
}
}
|