From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../src/examples/messaging/PoisonBean.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java new file mode 100644 index 0000000..2bdfcba --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java @@ -0,0 +1,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."); + } +} \ No newline at end of file -- cgit v1.2.3