Thanks to the standards implemented in the Jakarta EE 8 server, our MDB is 100% managed by the container. That's why we could just refer to the queue without looking back:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup",
propertyValue = "jms/JmsQueue"),
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue")
})
We could have built a consumer with our own hands, but it would involve three times as many code lines and would be synchronous.
We get our container producer from a session provided by our factory and made for our queue:
try (Connection connection = jmsFactory.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE)) {
producer = session.createProducer(jmsQueue);
...
}
Then, all we have to do is to create and send the message:
message = session.createTextMessage();
String msg = "Now it is " + new Date();
message.setText(msg);
System.out.println("Message sent to queue: " + msg);
producer.send(message);