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); TextMessage textMessage = (TextMessage) consumer.receive(1000); if (textMessage==null){ return "Received null"; } else { return "Payload="+textMessage.getText()+", JMSPriority="+textMessage.getJMSPriority()+", foo="+textMessage.getStringProperty("foo"); } } catch (Exception ex) { Logger.getLogger(JavaEESyncReceiverOld.class.getName()).log(Level.SEVERE, null, ex); } return null; } }
This example shows:
You have reached the last example