36 lines
919 B
Kotlin
36 lines
919 B
Kotlin
package drills.drill07.exercise2
|
|
|
|
import org.apache.activemq.ActiveMQConnectionFactory
|
|
import javax.jms.QueueConnectionFactory
|
|
import javax.jms.Session
|
|
import javax.jms.TextMessage
|
|
|
|
fun main() {
|
|
val url = "tcp://localhost:61616"
|
|
val factory: QueueConnectionFactory = ActiveMQConnectionFactory(url)
|
|
val connection = factory.createQueueConnection()
|
|
connection.start()
|
|
|
|
val session = connection.createQueueSession(
|
|
false,
|
|
Session.AUTO_ACKNOWLEDGE
|
|
)
|
|
|
|
val queue = session.createQueue("requestor")
|
|
val sender = session.createSender(queue)
|
|
|
|
val tmpQueue = session.createTemporaryQueue()
|
|
val receiver = session.createReceiver(tmpQueue)
|
|
|
|
val msg = session.createTextMessage("Hello Home!")
|
|
msg.jmsReplyTo = tmpQueue
|
|
|
|
sender.send(msg)
|
|
|
|
val replyMsg = receiver.receive() as TextMessage
|
|
println(replyMsg.text)
|
|
|
|
session.close()
|
|
connection.close()
|
|
}
|