Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Duplicate Messages sent

843830Aug 17 2004 — edited Aug 18 2004
Hi there,
I am trying to figure out why I receive duplicate messages from my message queue. We have our Entity Beans send out messages when their state changes. When the beans are deployed first, and their state changes, only a single message is sent out, but if the state of the bean is changed again, then multiple messages are sent out. I guess the message queue does not get flushed after the delivery of the messages. Can any one shed some light on this issue?
Here is my client code, which is gui.
try {
TopicConnectionFactory factory = serviceLocator.getTopicConnectionFactory("jms/TopicConnectionFactory");
Topic topic = serviceLocator.getTopic("jms/jtTopic");
TopicConnection connect = factory.createTopicConnection();
TopicSession session = connect.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
TopicSubscriber subscriber = session.createSubscriber(topic);
subscriber.setMessageListener(this);
System.out.println("Listening for messages on topic/rhythm-employee...");
// calls onMessage();
connect.start();
} catch (NamingException ne) {
ne.printStackTrace();
} catch (JMSException jme) {
jme.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

And here is the onMessage code:
public synchronized void onMessage(Message message) {
try {
ObjectMessage oMsg = (ObjectMessage) message;
String jobName = oMsg.getStringProperty("jobName");
String scnName = oMsg.getStringProperty("scnName");
if (oMsg.getStringProperty("actionType").equals("scene")) {
SceneTO sceneTO = (SceneTO) oMsg.getObject();
System.out.println("Scene Name: " + sceneTO.getSceneName());
}
final Object obj = oMsg.getObject();
Hashtable hash;
if (obj instanceof SceneTO) {
JTBase.jobLock.lock();
hash = (Hashtable) JTBase.Jobs.get(jobName);
if (!hash.containsKey(scnName)) {
hash.put(scnName,new Hashtable());
}
hash = (Hashtable) hash.get(scnName);
if (!hash.containsKey("Scene Info")) {
hash.put("Scene Info",new Hashtable());
}
hash = (Hashtable) hash.get("Scene Info");
if (hash.containsKey("data")) {
hash.remove("data");
}
hash.put("data",obj);

JTBase.jobLock.releaseLock();

// Refresh if needed
if(JTBase.jobName.equals(jobName) && JTBase.scnName.equals(scnName)) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateHeader(obj);
if (JTBase.tabName.equals("Scene Info")) {
updateMain("Refresh");
}
}
});
}
}
oMsg.clearBody();
message.acknowledge();
} catch(JMSException jmsE) {
JTBase.jobLock.releaseLock();
jmsE.printStackTrace();
}
}
Thanks in advance
-r
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2004
Added on Aug 17 2004
1 comment
163 views