Issue with JMS XAQueueSession
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   njr_frens
Posted On:   Sunday, May 9, 2010 09:55 AM

My Application Server is SAP NetWeaver Application Server CE7.1 While I'm creating XAQueueSession and publishing, the messages are not published into the queue. Is there any error in my code? public class JMSSender extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { static final long serialVersionUID = 1L; PrintWriter out; private XAQueueConnectionFactory queueConnectionFactory; private Queue queue; private QueueSession queueSession = null; private QueueSender queueSender = null; private TextMessage message = null; private XAQueueSession queueSessionXA = null; private XAQueueConnection queueConnection    More>>

My Application Server is SAP NetWeaver Application Server CE7.1

While I'm creating XAQueueSession and publishing, the messages are not published into the queue.

Is there any error in my code?


			
public class JMSSender extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;

PrintWriter out;

private XAQueueConnectionFactory queueConnectionFactory;
private Queue queue;
private QueueSession queueSession = null;
private QueueSender queueSender = null;
private TextMessage message = null;

private XAQueueSession queueSessionXA = null;
private XAQueueConnection queueConnection = null;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
out = response.getWriter();

try {
initQueue();
printQueue("Q Before");
publishMessage(false);
} catch (Exception e) {
e.printStackTrace(out);
} finally {
printQueue("Finally");
closeJMS();
}
}

public void publishMessage(boolean rollBackFlag) throws Exception {
int rand = new Random(100).nextInt();
for ( int i = 1; i < 5; i++) {
message = queueSession.createTextMessage();
message.setText("Current Time is (" + (new Date().getTime() + rand + i) + ") :: " + new Date());
out.println("
" + "Sending message :: " + message.getText());
queueSender.send(message);

if (rollBackFlag && (i == 3)) {
throw new Exception("Throwing Exception");
}
}
}

private void closeJMS() {
try {
if (queueSession != null) {
queueSession.close();
}
if (queueSessionXA != null) {
queueSessionXA.close();
}
if (queueConnection != null) {
queueConnection.close();
}
} catch (Exception e) {
out.println("
");
e.printStackTrace(out);
}
}

public void printQueue(String desc) {
try {
out.println( "
" + desc + " Queue contents :: " );
QueueBrowser browser = queueSession.createBrowser(queue);
Enumeration en = browser.getEnumeration();
while (en.hasMoreElements()) {
TextMessage queueBrMessage = en.nextElement();
out .println( "
" + queueBrMessage.getText());
}
} catch (JMSException e) {
out.println("
");
e.printStackTrace(out);
}
}

public void initQueue() throws Exception {
InitialContext ctx = getInitialContext();

queueConnectionFactory = (XAQueueConnectionFactory) ctx.lookup("jmsfactory/default/VQConFactoryXA");
queue = (Queue) ctx.lookup("jmsqueues/default/VQueue");

queueConnection = queueConnectionFactory.createXAQueueConnection();
queueSessionXA = queueConnection.createXAQueueSession();
queueSession = queueSessionXA.getQueueSession();

queueSender = queueSession.createSender(queue);
queueConnection.start();
}

public InitialContext getInitialContext() throws Exception {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
properties.put(Context.PROVIDER_URL, "localhost:50004");
properties.put(Context.SECURITY_PRINCIPAL, "Administrator");
properties.put(Context.SECURITY_CREDENTIALS, "atlas123");
properties.put("force_remote", "true");
InitialContext context = new InitialContext(properties);
return context;
}
}
   <<Less

Re: Issue with JMS XAQueueSession

Posted By:   njr_frens  
Posted On:   Sunday, May 9, 2010 09:56 AM

Intead of XAQueueSession, if I create normal queue session(non XA) like below, it is publishing messages

queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

What is wrong with XAQueueSession?
About | Sitemap | Contact