November 2018
Intermediate to advanced
388 pages
9h 5m
English
Let's now write the Consumer class to receive the message from the queue. On the Consumer side, we still need the JMSContext to retrieve the messages from the queue. The code looks similar to that which we wrote for the producer:
class Consumer { @Inject private lateinit var initialContext: InitialContext fun receiveMessage(): String { val queue = initialContext.lookup("jms/PointToPointQueue") as Queue val connectionFactory = initialContext.lookup("jms/__defaultConnectionFactory") as ConnectionFactory val message = connectionFactory .createContext() .createConsumer(queue) .receiveBody(String::class.java) println("Message received $message") return message }}
We looked up the queue using a JNDI lookup and we loaded ...
Read now
Unlock full access