Problems with iMQ 2.0 QueueBrowser.
I am working in IMQ2.0.I think the queuebrowser is not
working.Please look into it.Though i am using
queuebrowser with a selector,i also tried without
selector.Please send me the solution as soon as
possible.I am attaching standalone IMQ applications of
sender and receiver.Though without the queubrowser the
codes are working fine.
==================Receiver Code================
import java.util.*;
import java.io.*;
import javax.naming.*;
import javax.jms.*;
public class NewReceiver implements MessageListener {
private QueueConnectionFactory factory;
private Queue queue;
private QueueSessionsession= null;
private QueueConnectionconnection= null;
private QueueReceiverqueueReceiver= null;
private QueueBrowser queueBrowser=null;
private MessagemsgReceived= null;
private static final String LOOKUP_STRING_FACTORY = "SampleFactory";
private static final String LOOKUP_STRING_QUEUE= "SampleQueue";
public NewReceiver(String name) {
try
{
out("Looking up the initial context from JNDI");
Context initialContext = getInitialContext();
out("Looking up the queue connection factory from JNDI");
factory = (QueueConnectionFactory) initialContext.lookup(LOOKUP_STRING_FACTORY);
out(LOOKUP_STRING_FACTORY + ": " + factory);
out("Looking up the queue from JNDI");
queue = (Queue) initialContext.lookup(LOOKUP_STRING_QUEUE);
out(LOOKUP_STRING_QUEUE + ": " + queue);
connection = factory.createQueueConnection();
out("Starting the Connection ");
session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
String selector=name;
//creatign a browser with a message selector
queueBrowser=session.createBrowser(queue,selector);
//browsing thru the queue and getting enumeration
Enumeration enum=queueBrowser.getEnumeration();
out("B4 QUEUEBROWSER");
//retreiving the elements browsed
while(enum.hasMoreElements())
{
out("in queubrowser");
Message m = (Message)enum.nextElement();
if ( m instanceof TextMessage) {
TextMessage txtMsg = (TextMessage) m;
out("message is"+txtMsg);
}
}
out("after QUEUEBROWSER");
queueBrowser.close();
out("Creating a
QueueReceiver");
queueReceiver = session.createReceiver(queue,"name ='"+selector.trim()+"'");
out("selector"+queueReceiver.getMessageSelector());
queueReceiver.setMessageListener(this);
connection.start();
}catch (Exception ex){
ex.printStackTrace();
}
}
public void onMessage(Message m) {
String msg =null;
if (m instanceof TextMessage)
{
try
{
TextMessage txtMsg = (TextMessage) m;
msg = txtMsg.getText();
System.out.print("message property"+txtMsg.getStringProperty("name"));
}
catch (Exception ex)
{
ex.printStackTrace();
}
}else {
System.out.println("Not a text Message...");
}
}
public static void main(String args[] ) {
NewReceiver receiver = new NewReceiver(args[0]);
}
private void out(String message) {
System.out.println(message);
}
private static InitialContext getInitialContext()
throws NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.netscape.server.jms.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "/jms");
return new InitialContext(env);
}
}
==================Receiver Code================
==================Sender Code================
import java.util.*;
import java.io.*;
import javax.naming.*;
import javax.jms.*;
public class NewSender {
private QueueConnectionFactory factory;
private Queue queue;
private QueueSessionsession= null;
privateQueueConnectionconnection= null;
privateQueueSenderqueueSender= null;
static int i=1;
private static final String LOOKUP_STRING_FACTORY = "SampleFactory";
private static final String LOOKUP_STRING_QUEUE= "SampleQueue";
private boolean verbose = true;
public NewSender(String name,String messageBody) {
try
{
out("Looking up the initial context from JNDI");
Context initialContext = getInitialContext();
out("Looking up the queue connection factory from JNDI");
factory = (QueueConnectionFactory) initialContext.lookup(LOOKUP_STRING_FACTORY);
out(LOOKUP_STRING_FACTORY + ": " + factory);
out("Looking up the queue from JNDI");
queue = (Queue) initialContext.lookup(LOOKUP_STRING_QUEUE);
out(LOOKUP_STRING_QUEUE + ": " + queue);
connection = factory.createQueueConnection();
out("Starting the Connection in sender ");
session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
out("Creating a QueueSender");
queueSender = session.createSender(queue);
out("Building a message" );
TextMessage msgSent = session.createTextMessage();
msgSent.setText(messageBody);
msgSent.setStringProperty("name",name.trim());
queueSender.send(msgSent);
}
catch(NameNotFoundException e) {
System.out.print("The application could not locate the JMS");
System.out.println(" administered objects ");
System.out.println("in the file system service provider.");
System.exit(1);
}catch (Exception ex){
ex.printStackTrace();
}
}
public static void main(String args[] ) {
NewSender sender =new NewSender(args[0],args[1]);
}
private void out(String message) {
System.out.println(message);
}
private static InitialContext getInitialContext()
throws NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.netscape.server.jms.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "/jms");
return new InitialContext(env);
}
}
==================Sender Code================

