Last active
November 30, 2016 10:31
-
-
Save TRBaldim/9edf87f0ca7ff1a45cc650153dc2a5c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.ibm.mq.jms.MQQueueConnectionFactory | |
| import com.ibm.mq.jms.JMSC | |
| import scala.io.Source | |
| import javax.jms.DeliveryMode | |
| import javax.jms.Session | |
| def toRun(){ | |
| val fileName = "/home/my_home/path/local_file" | |
| val cf = new MQQueueConnectionFactory(); | |
| cf.setHostName("1.1.1.1"); | |
| cf.setPort(1111); | |
| cf.setChannel("CHANNEL.NAME"); | |
| cf.setQueueManager("QMNG_NAME"); | |
| cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP) | |
| val conn = cf.createQueueConnection("USER_NAME", "PWD") | |
| val session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE) | |
| val queue = session.createQueue("MY.QUEUE.NAME") | |
| //For producer | |
| val producer = session.createProducer(queue) | |
| producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT) | |
| //For Consumer | |
| val consumer = session.createConsumer(queue) | |
| conn.start() | |
| for (line <- Source.fromFile(fileName).getLines()){ | |
| var message = session.createTextMessage(line) | |
| message.setStringProperty("header", "add a header if you want") | |
| producer.send(message) | |
| } | |
| val message = consumer.receive(1000) | |
| session.close() | |
| conn.close() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment