Skip to content

Instantly share code, notes, and snippets.

@sachin-handiekar
Created November 3, 2011 21:51
Show Gist options
  • Save sachin-handiekar/1337894 to your computer and use it in GitHub Desktop.
Save sachin-handiekar/1337894 to your computer and use it in GitHub Desktop.
Send XML Type payload to Oracle AQ using Spring JMS
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!!!");
}
}
@saruharshu
Copy link

bro, can you please provide bean xml file also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment