Here is a simple Java EE session bean which extends the earlier example to demonstrate how to use the JMS 2.0 simplified API and an injected JMSContext to synchronously receive a message and extract the message delivery options and message properties we set earlier
@Stateless @LocalBean public class JavaEESyncReceiverNewCDIWithProperties { @Inject @JMSConnectionFactory("java:global/jms/demoConnectionFactory") // <== could omit this and use the default private JMSContext context; @Resource(lookup = "java:global/jms/demoQueue") Queue inboundQueue; public String receiveMessageNewCDIWithProperties() { try { JMSConsumer consumer = context.createConsumer(inboundQueue); Message message = consumer.receive(1000); if (message==null){ return "Received null"; } else { return "Body="+message.getBody(String.class) +", JMSPriority="+message.getJMSPriority()+", foo="+message.getStringProperty("foo"); } } catch (Exception ex) { Logger.getLogger(JavaEESyncReceiverOld.class.getName()).log(Level.SEVERE, null, ex); } return null; } }
In addition to the features demonstrated in JavaEESyncReceiverNewCDI, this example shows:
You have reached the last example