• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMS MessageListner not Consuming Messages(onMessage() is not calling)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


here problem is onMessage() is not calling for some times, when i do restart server its calling onMessage(). but it should call when ever message arrives in Queue, its not happning and no Error or Exception thrown.

have problemw with JMS Message listener, and its not consuming message from queue, once I restart server then its sending message form queue, no exception or error thrown.

onMessage() in message listener is not firing always..how to resolve the issue.

Even no Exception showed in the server logs. I am using sun java server8.2

flow is GatewayServlet init()--> calls -->GatewayMessageReceiver init() method when GatewayServlet loads into sun java applicaiton server or deployed into sun java app server.

Then init() method in GatewayMessageReceiver class creates jms session and queue connection.

Here GatewayMessageReceiver implements Message listner class...

Here problem is onMessage() is not calling for some times, when I do restart server its calling onMessage(). but it should call when ever message arrives in Queue, its not happning and no Error or Exception thrown.

I want to implement Exception listner but its thrwoing Errors

code set

import java.util.*;
import java.io.*;
import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class GatewayServlet extends HttpServlet {

private GatewayMessageReceiver receiver = null;


/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
receiver = new GatewayMessageReceiver(); //here iam calling my GatewayMessageReceiver for JMS connection creations
info(""+receiver);
}

/** Destroys the servlet
*/
public void destroy() {
if (receiver != null) {
receiver.destroy();
}
}


protected void processGatewayRequest(ServletRequest request, ServletResponse response)
throws ServletException, java.io.IOException {
//doing some business logic



}

protected void processRequest(ServletRequest request, ServletResponse response)
throws ServletException, java.io.IOException {
Logger.getGatewayLogger(GeneralConfigurator.getInstance().getUtility()).debug("Host sending request is:"+request.getRemoteHost());
//check whether it's a push request
processGatewayRequest(request, response);
}
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
public void service(ServletRequest request, ServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}

public void doGet(ServletRequest request, ServletResponse response)
throws ServletException, java.io.IOException {
service(request, response);
}

public void doPost(ServletRequest request, ServletResponse response)
throws ServletException, java.io.IOException {
service(request, response);
}


}


MS MESSAGE LISTNER IS

mport javax.jms.*;
import java.util.logging.*;
/**
*
* @author Administrator
*/
public class GatewayMessageReceiver implements MessageListener {

private QueueConnection connection = null;

/** Creates a new instance of GatewayMessageReceiver */
public GatewayMessageReceiver() {
super();

init();
}

private void init() {
QueueSession session = null;
QueueReceiver queueReceiver = null;

try{
String queueName = "infoQueue";//its sun java app sever queue name
String qcfName = "infoQueueCF";//connectionfactory created in sun java app sever

Logger.log.log(Level.INFO, "Queue name: "+queueName);
Logger.log.log(Level.INFO, "Queue CF name: "+qcfName);

QueueConnectionFactory qcf =
(QueueConnectionFactory)JndiUtilities.get(qcfName);
Logger.log.log(Level.INFO, "Queue CF: "+qcf);
Queue queue =
(Queue)JndiUtilities.get(queueName);
Logger.log.log(Level.INFO, "Queue: "+queue);
// Creating a QueueConnection to the Message service");
connection = qcf.createQueueConnection();
// Creating a session within the connection
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// Creating a QueueReceiver
queueReceiver = session.createReceiver(queue);
// setting up a message listener
queueReceiver.setMessageListener(this);
//Starting the Connection
connection.start();
} catch (Throwable t) {
Logger.log(Level.SEVERE, "Failed to start queue listener for business messages", t);
}
}

public void destroy() {
try {
if (connection != null) {
connection.close();
}
} catch (Throwable t) {
Logger.log(Level.SEVERE, "Failed to close queue connection", t);
}
}

public void onMessage(javax.jms.Message message) {
String ut = null;
try {
String utm = message.getStringProperty(IConstants.UTILITY_TAG);
int bcDelay = message.getIntProperty(IConstants.BC_DELAY);

//it must be an ObjectMessage!
ObjectMessage omsg = (ObjectMessage)message;

//Here iam doing business logic

} catch (Throwable t) {
Logger.log(Level.SEVERE, "Failed to process business message", t);
}
}

}

THE JNDI UTILITIES CLASS

import javax.naming.*;
import javax.sql.*;

/**
*
* @author Administrator
*/
public class JndiUtilities {
private static Context context = null;

static {
setJndiContext();
}

/** Creates a new instance of JndiUtilities */
private JndiUtilities() {
super();
}

private static void setJndiContext() {
try {
context = new InitialContext();
} catch (Exception e) {
System.err.println("ERROR getting JNDI context: "+e);
}
}

public static Object get(String name) {
if (context == null) {
setJndiContext();
if (context == null) return null;
}

Object obj;

try {
obj = context.lookup(name);
} catch (Exception e) {
obj = null;
System.err.println("ERROR getting JNDI resource named \""+name+"\": "+e);
}
return obj;
}

}

please help me in this case
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic