Why Messages in Topic is always = 0 ?
erasmomarciano Jul 5, 2013 4:08 PMHi
I have create this class in Java but when I open the web-console by Jboss I see always
Messages in Topic = 0
Metric | Actual | |
Messages in Topic: | 0 | |
In Delivery: | 0 |
package org.jboss.book.jms.ex1;
import java.util.Hashtable;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* A JMS client example program that sends a TextMessage to a Topic
*
* @author Scott.Stark@jboss.org
* @version $Revision: 1.9 $
*/
public class TopicSendClient
{
TopicConnection conn = null;
TopicSession session = null;
Topic topic = null;
Topic INITIAL_CONTEXT_FACTORY=null;
Topic PROVIDER_URL= null;
public void setupPubSub()
throws JMSException, NamingException
{
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "remote://localhost:4447");
props.put("java.naming.rmi.security.manager", "yes");
props.put(Context.SECURITY_PRINCIPAL, "quickstartUser");
props.put(Context.SECURITY_CREDENTIALS, "quickstartPassword");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
// Get the initial context with given properties
Context iniCtx = new InitialContext(props);
Object tmp = iniCtx.lookup("jms/RemoteConnectionFactory");
TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
conn = tcf.createTopicConnection();
topic = (Topic) iniCtx.lookup("jms/topic/test");
session = conn.createTopicSession(false,
TopicSession.AUTO_ACKNOWLEDGE);
conn.start();
}
public void sendAsync(String text)
throws JMSException, NamingException
{
System.out.println("Begin sendAsync");
// Setup the pub/sub connection, session
setupPubSub();
// Send a text msg
for (int i = 0; i < 1000; i++) {
TopicPublisher send = session.createPublisher(topic);
TextMessage tm = session.createTextMessage("erasmo Topic" + i);
send.publish(tm);
System.out.println("sendAsync, sent text=" + tm.getText() +i);
send.close();
}
System.out.println("End sendAsync");
}
public void stop()
throws JMSException
{
conn.stop();
session.close();
conn.close();
}
public static void main(String args[])
throws Exception
{
System.out.println("Begin TopicSendClient, now=" +
System.currentTimeMillis());
TopicSendClient client = new TopicSendClient();
for (int i = 0; i < 1000; i++) {
client.sendAsync("A text msg, now="+System.currentTimeMillis() +1);
}
client.stop();
System.out.println("End TopicSendClient");
System.exit(0);
}
}
I studied this guide
Can I help me?