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 ...