Created
November 3, 2011 21:51
-
-
Save sachin-handiekar/1337894 to your computer and use it in GitHub Desktop.
Send XML Type payload to Oracle AQ using Spring JMS
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
package com.sachinhandiekar.oracle.aq; | |
import java.sql.Connection; | |
import java.sql.SQLException; | |
import javax.jms.JMSException; | |
import javax.jms.Message; | |
import javax.jms.Session; | |
import javax.sql.DataSource; | |
import oracle.jms.AQjmsSession; | |
import oracle.xdb.XMLType; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.support.ClassPathXmlApplicationContext; | |
import org.springframework.jms.core.JmsTemplate; | |
import org.springframework.jms.core.MessageCreator; | |
public class Main { | |
public static void main(String[] args) { | |
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); | |
JmsTemplate jmsTemplate = (JmsTemplate) ctx.getBean("jmsTemplate"); | |
final DataSource dataSource = (DataSource) ctx.getBean("dataSource"); | |
final String xmlMessage = "<sample>hello aq test 2</sample>"; | |
jmsTemplate.send("q_sample", new MessageCreator() { | |
public Message createMessage(Session session) throws JMSException { | |
Connection conn = null; | |
XMLType payload = null; | |
try { | |
conn = dataSource.getConnection(); | |
payload = XMLType.createXML(conn, xmlMessage); | |
} | |
catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
finally { | |
try { | |
conn.close(); | |
} | |
catch (SQLException e) { | |
// ignore it | |
} | |
} | |
Message msg = ((AQjmsSession) session).createORAMessage(payload); | |
return msg; | |
} | |
}); | |
System.out.println("Message Sent!!!"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bro, can you please provide bean xml file also