How it works...

We start by asking the application server a JMS context instance:

@Injectprivate JMSContext context;

We also send a reference to the queue we want to work with:

@Resource(lookup = "jms/JmsQueue")private Destination queue;

Then, using the context, we create a producer to send the message to the queue:

context.createProducer()        .setDeliveryMode(DeliveryMode.PERSISTENT)        .setDisableMessageID(true)        .setDisableMessageTimestamp(true)        .send(queue, user);

Pay attention to these three methods:

  • setDeliveryMode: This method can be PERSISTENT or NON_PERSISTENT. If using PERSISTENT, the server will take special care of the message and not lose it.
  • setDisableMessageID: This one is used for creating MessageID, which increases the server effort ...

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.