Let's continue with the previous sample client to write a message consumer through the message listener. The message listener is an alternative to the receive method of the JMSConsumer class we saw in the Queues and Topics sections.
The message listener is represented by the javax.jms interface. MessageListener lets the client listen to the incoming messages and execute an action after the reception of the message. This is a sample of the message listener listening to the questionary messages:
public class MessageQueueListener implements MessageListener {
...
private Questionary questionary;
@Override
public void onMessage(Message message) {
ObjectMessage objectMessage = (ObjectMessage) message;
try {
Questionary questionary = objectMessage.getBody(Questionary.class);
questionary.setApproved(true);
this.questionary...