Publish once but get 8 replicated message on the topic
treefield Aug 7, 2007 12:22 AMHi,
I looked around and found some sample code to publish to a JBoss topic...
public static boolean publish(String xml) throws Exception
{
log.info("Creating jndi context - alternatively use a jndi.properties");
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://myserver:1099");
InitialContext ctx = new InitialContext(properties);
Topic topic = (Topic) ctx.lookup("topic/myTopic");
TopicConnectionFactory tcf = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
TopicConnection tc = tcf.createTopicConnection("user","pwd");
try
{
TopicSession ts = tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher publisher = ts.createPublisher(topic);
TextMessage message = ts.createTextMessage(xml);
publisher.send(message);
publisher.close();
tc.close();
return true;
}
catch(Exception e){
log.error("Exception thrown trying to send to topic", e);
return false;
}
finally
{
tc.close();
}
}If I disable the subscriber to the topic and look in the JMS_MESSAGES table (HA JMS is configured), I find 8 duplicated messages. There is no looping and only a single subscriber has been configured. Since this is the first tested topic other than the samples that come already installed, this is the only custom configuration so far. I set up the topic in the *-service.xml file as follows...
<mbean code="org.jboss.mq.server.jmx.Topic" name="jboss.mq.destination:service=Topic,name=myTopic"> <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends> <depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends> <attribute name="SecurityConf"> <security> <role name="guest" read="true" write="true"/> <role name="publisher" read="true" write="true" create="false"/> <role name="durpublisher" read="true" write="true" create="true"/> </security> </attribute> </mbean>
I am not sure what could be causing the superfluous messages. Is there a known issue with publishing to topics? I am using JBoss 4.0.2 and JDK 1.5.
Thanks in advance!
Theresa