• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMS Queue taking long time to run

 
Ranjani Sivaraman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i'm new bee to jms..trying one sample example from the net.
I have created 2 java class one for sender and other for receiver and
created new service.xml file in conf folder of jboss to configure the queue name.
I created one jsp file to call the receiver and sender classes.
After deploying the application in jboss , when i tried to debug it, it got struck in looking up the queue. I used the sysout after every line for debugging.. When it comes to the line

Queue queue = (Queue) ctx.lookup("queue/queue0")

Its taking longer tym nearly 45 mins then ended with no output. After that no line was printed in console.
I ll paste my code here..
Kindly help...


Sender.java

<Code>
import java.util.Properties;

import javax.naming.Context;

import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.QueueSender;
import javax.jms.DeliveryMode;
import javax.jms.QueueSession;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;


public class Sender{
public static Context getInitialContext( ) throws javax.naming.NamingException {
System.out.println("====java1============================");
Properties p = new Properties( );
p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
System.out.println("======================java2============================");
return new javax.naming.InitialContext(p);
}


public void getMessage(){
try{
System.out.println("1");
Context ctx = getInitialContext();
// lookup the queue object
System.out.println("2");
Queue queue = (Queue) ctx.lookup("queue/queue0");
System.out.println("3");
// lookup the queue connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.
lookup("queue/connectionFactory");
System.out.println("4");
// create a queue connection
QueueConnection queueConn = connFactory.createQueueConnection();
System.out.println("5");
// create a queue session
QueueSession queueSession = queueConn.createQueueSession(false,
Session.DUPS_OK_ACKNOWLEDGE);
System.out.println("6");
// create a queue sender
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

// create a simple message to say "Hello"
TextMessage message = queueSession.createTextMessage("Hello");
System.out.println("7");
// send the message
queueSender.send(message);

// print what we did
System.out.println("sent: " + message.getText());

// close the queue connection
queueConn.close();
}catch(Exception e){
System.out.println(e.getMessage());
}


}

Receiver.java

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.QueueSession;
import javax.jms.QueueReceiver;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;

public class Receiver{
public static Context getInitialContext( ) throws javax.naming.NamingException {

Properties p = new Properties( );
p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
return new javax.naming.InitialContext(p);
}
/**
* @param args
*/
public void receiveMessage(){
try{
System.out.println("444");
// get the initial context
Context ctx = getInitialContext();

// lookup the queue object
Queue queue = (Queue) ctx.lookup("queue/queue0");

// lookup the queue connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.
lookup("queue/connectionFactory");

// create a queue connection
QueueConnection queueConn = connFactory.createQueueConnection();

// create a queue session
QueueSession queueSession = queueConn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
// create a queue receiver
QueueReceiver queueReceiver = queueSession.createReceiver(queue);

// start the connection
queueConn.start();

// receive a message
TextMessage message = (TextMessage) queueReceiver.receive();

// print the message
System.out.println("received: " + message.getText());

// close the queue connection
queueConn.close();
} catch(Exception e){
System.out.println(e.getMessage());
}

}

CallJms.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" import="com.cts.Test2"%>
<%@page language="java" import="com.cts.Testrxr2"%>
<html>
<%Test2 obj1 = new Test2();
Testrxr2 obj2 = new Testrxr2();
obj1.getMessage();
obj2.receiveMessage();
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hiiiiiii
</body>
</html>

jboss-dest-service.xml

<server>
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.messaging.destination:service=Queue,name=queue0">
<depends optional-attribute-name="ServerPeer">
jboss.messaging:service=ServerPeer</depends>
</mbean>
</server>

</Code>

OUTPUT:

1

====java1============================

======================java2============================
2

After that no output displayed in console..

im using jboss 6.0.1

Is there any wrong in the code or any configuration problem ..why its taking long tym???

Thanks in advance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic