lm-sistemi-software-distrib.../src/main/kotlin/drills/drill07/exercise1/point2/Sender.kt

32 lines
734 B
Kotlin

package drills.drill07.exercise1.point2
import org.apache.activemq.ActiveMQConnectionFactory
import javax.jms.QueueConnectionFactory
import javax.jms.Session
fun main() {
val url = "tcp://localhost:61616"
val factory: QueueConnectionFactory = ActiveMQConnectionFactory(url)
val connection = factory.createQueueConnection()
val session = connection.createQueueSession(
true,
Session.SESSION_TRANSACTED
)
val queue = session.createQueue("transacted")
val sender = session.createSender(queue)
val msg = session.createMessage()
repeat(10) {
msg.setIntProperty("value", it)
sender.send(msg)
}
session.commit()
session.close()
connection.close()
}