onMessage method doesn't get called.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   giuseppe_sarno
Posted On:   Friday, July 4, 2003 08:57 AM

Hi, I'm new to JMS and also to Java and I'm trying to learn a basic PTP JMS system. The CLient-Server Architecture works fine when I use the send-receive paradigm. But now I'm having problems with the send-Listen one. Basically when running the client the onMessage method on the Server side is not called. I've been looking at example on the web and it all seems ok. Has anyone got an idea why this code doesn't work ? CODE: import javax.jms.*; import java.io.*; import javax.naming.*; import java.util.*; import java.util.Hashtable; public class JMSListener implements MessageListener { protected Context jndiContext =null;    More>>

Hi,
I'm new to JMS and also to Java and I'm trying to
learn a basic PTP JMS system.
The CLient-Server Architecture works fine when I use the
send-receive paradigm. But now I'm having problems with the send-Listen one.
Basically when running the client the onMessage method on the Server side is not called.
I've been looking at example on the web and it all seems ok.
Has anyone got an idea why this code doesn't work ?
CODE:

import javax.jms.*;
import java.io.*;
import javax.naming.*;
import java.util.*;
import java.util.Hashtable;

public class JMSListener implements MessageListener
{

protected Context jndiContext =null;
protected QueueConnectionFactory qConnectionFactory = null;
protected QueueConnection qConnection = null;
protected QueueSession qSession = null;
protected String qName = null;
protected Queue queue = null;
protected QueueReceiver qReceiver = null;

public JMSListener(String st)
{
System.out.println("INIT:");
qName=st;
try{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");
env.put(Context.PROVIDER_URL, "ormi://localhost:23791/");

//0. Get the context
jndiContext = new InitialContext(env);
}
catch (NamingException e)
{
System.out.println("Could not create JNDI API " + "context:" + e.toString());
System.exit(1);
}

try{
//1. get connection factory
qConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("jms/QueueConnectionFactory");
//2. get Q
queue = (Queue) jndiContext.lookup (new String ("jms/"+ qName));
}

catch (NamingException e)
{
System.out.println("JNDI API lookup failed" + e.toString());
System.exit(1);
}

try
{
//3 . Create a connection
qConnection = qConnectionFactory.createQueueConnection();
//4. Create Session (With properties)
qSession = qConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
if (qSession != null)
{System.out.println("Session not null");}
}
catch (JMSException e)
{
System.out.println("Create Conn/Sess Exception: " + e.toString());
System.exit(1);
}

try{

qReceiver = qSession.createReceiver(queue);

qReceiver.setMessageListener(this);

qConnection.start();
}
catch (JMSException e)
{
System.out.println("Create Sender Exception: " + e.toString());
System.exit(1);
}
}

public void onMessage(Message m)
{
System.out.println("Message received:");
}
public static void main(String[] args)
{

JMSListener jMSListener = new JMSListener("FirstQ");
while (true)
{
}
}
}

   <<Less
About | Sitemap | Contact