Created
September 6, 2011 23:05
-
-
Save solo-seven/1199252 to your computer and use it in GitHub Desktop.
This file contains 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
package com.redhat.demo.msg.web; | |
import java.net.InetAddress; | |
import javax.jms.MessageProducer; | |
import javax.jms.Queue; | |
import javax.jms.XAConnection; | |
import javax.jms.XAConnectionFactory; | |
import javax.jms.XASession; | |
import javax.naming.InitialContext; | |
import javax.transaction.TransactionManager; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
@Path("/restqueue") | |
public class RestQueueLauncher { | |
@GET | |
public String testQueue() { | |
try { | |
InitialContext ic = new InitialContext(); | |
XAConnectionFactory cf = (XAConnectionFactory) ic.lookup("XAConnectionFactory"); | |
TransactionManager tm = (TransactionManager)ic.lookup("java:/TransactionManager"); | |
tm.begin(); | |
XAConnection conn = cf.createXAConnection(); | |
conn.start(); | |
XASession sess = conn.createXASession(); | |
Queue queue = (Queue) ic.lookup("/queue/WorkQueue"); | |
MessageProducer producer = sess.createProducer(queue); | |
InetAddress addr = InetAddress.getLocalHost(); | |
producer.send(sess.createTextMessage("Test Message : " | |
+ addr.getHostName())); | |
producer.close(); | |
conn.close(); | |
sess.close(); | |
tm.commit(); | |
System.out.println("Message sent."); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return "SUCCESS"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment