to publish a object msg it takes 0.5sec
Vel Pandian <[email protected]>
| Newsgroups | gmane.comp.java.openjms.user |
|---|---|
| Message-ID | <[email protected]> |
Hi
I am using open JMS
I had checked the time difference in the execution of the publishing a
msg it took around 500 milli seconds. is there any way to reduce it,
or any other suggestion
plzz help
thnx Vel Pandian
here is the following code just copy paste and run it works as the msg
consumer and producer
import java.util.Hashtable;
import javax.jms.*;
import javax.naming.*;
public class MessageSink implements MessageListener
{
private TopicConnection topicConnection;
private TopicSession topicSession;
private Topic topic;
static private TopicSubscriber topicSubscriber;
//static private Logger myLogger;
TopicPublisher topicPublisher;
MessageSink()
{
try
{
// create a JNDI context
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.exolab.jms.jndi.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "rmi://localhost:1099/");
//properties.put(Context.PROVIDER_URL, "tcp://localhost:3035/");
Context context = new InitialContext(properties);
// retrieve topic connection factory
TopicConnectionFactory topicConnectionFactory =
(TopicConnectionFactory) context
.lookup("JmsTopicConnectionFactory");
// create a queue connection
topicConnection = topicConnectionFactory.createTopicConnection();
// create a topic session
// set transactions to false and set auto acknowledgement
of receipt of messages
topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
// retrieve queue
topic = (Topic) context.lookup("topic1");
// create a queue recevier and associate to the retrieved queue
topicSubscriber = topicSession.createSubscriber(topic);
topicPublisher = topicSession.createPublisher(topic);
// associate message listener
topicSubscriber.setMessageListener(this);
// start delivery of incoming messages
topicConnection.start();
} catch (NamingException e)
{
e.printStackTrace();
} catch (JMSException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
MessageSink messageSink = new MessageSink();
long startTime = System.currentTimeMillis();
messageSink.publish();
System.out.println("Total time take " +
(System.currentTimeMillis() - startTime));
}
public void publish()
{
System.out.println("listening");
try {
long startTime = System.currentTimeMillis();
ObjectMessage msg = topicSession.createObjectMessage();
System.out.println("time for creating objectmessage " +
(System.currentTimeMillis() - startTime));
msg.setObject("vel pandian");
startTime = System.currentTimeMillis();
topicPublisher.publish(msg);
System.out.println("topicPublisher " +
(System.currentTimeMillis() - startTime));
} catch(Exception e) {
e.printStackTrace();
}
}
// process incoming queue messages
public void onMessage(Message message)
{
System.out.println("onMessage Called .... ");
try
{
String messageText = null;
if (message instanceof ObjectMessage)
{
ObjectMessage objectMessage = (ObjectMessage) message;
System.out.println(objectMessage.getObject());
}
} catch (JMSException e)
{
e.printStackTrace();
}
}
}
-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start! http://www.idcswdc.com/cgi-bin/survey?id5hix