[ 
https://issues.apache.org/jira/browse/AMQ-6194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15179807#comment-15179807
 ] 

Christopher L. Shannon commented on AMQ-6194:
---------------------------------------------

Thanks for the test case.  I took your example and re-wrote it slightly with 
JUnit to demonstrate the issue and uploaded it as an attachment.   

[~gtully], If you run the test case you will see that the statistics report 
back a message count of 2 instead of 1.  The issue here is pretty simple, it's 
on line 857 of the Queue class: 
https://github.com/apache/activemq/blob/master/activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java#L857

The problem is the temp queue is part of a transaction, but since its store is 
null that if statement is always true so it executes the messageSent() method 
there and also again when the transaction completes which leads to the 
statistics updating twice.

Seems like we could just delete the {{store == null}} part because I think any 
non temporary destination should always have a store.  Could also just change 
it to {{if ((store == null && !destination.isTemporary()) || 
(!context.isInTransaction() && !message.isPersistent()))}}

But I wanted to run it by you first to see what you think since you were the 
last person to have touched that line in this commit 
https://git-wip-us.apache.org/repos/asf?p=activemq.git;a=commit;h=54e2e3bef290d7455d9d1ba3420d12dc4805b339

> Deleting a temporary queue creates a warning message in the broker
> ------------------------------------------------------------------
>
>                 Key: AMQ-6194
>                 URL: https://issues.apache.org/jira/browse/AMQ-6194
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: Broker, JMS client
>    Affects Versions: 5.12.1, 5.13.1
>            Reporter: David Dou
>            Assignee: Christopher L. Shannon
>            Priority: Minor
>         Attachments: AMQ6194Test.java
>
>
> When deleting a temporary queue, the ActiveMQ 5.13.1 (and 5.12.2) broker logs 
> the following warning message:
> {noformat}
> INFO  [ActiveMQ NIO Worker 111] [TempQueue] 
> temp-queue://ID:brokerHostname-57582-1455804170203-8569:1:1 on dispose, purge 
> of 1 pending messages: 
> org.apache.activemq.broker.region.cursors.VMPendingMessageCursor@e0f6196
> WARN  [ActiveMQ NIO Worker 111] [Queue] 
> temp-queue://ID:brokerHostname-57582-1455804170203-8569:1:1 after purge of 1 
> messages, message count stats report: 1
> {noformat}
> The cause of this warning seems to be the publication of a "ghost" message 
> when sending a single message on the temporary queue from a transacted 
> session, as demonstrated by this test class:
> {code:java}
> import java.text.SimpleDateFormat;
> import java.util.Date;
> import javax.jms.Connection;
> import javax.jms.JMSException;
> import javax.jms.MessageProducer;
> import javax.jms.Session;
> import javax.jms.TemporaryQueue;
> import javax.jms.TextMessage;
> import org.apache.activemq.ActiveMQConnectionFactory;
> public class GhostMessageOnTempQueueWithTransactedSessionDemo {
>     public static void main(final String[] args) throws JMSException {
>         final ActiveMQConnectionFactory factory = new 
> ActiveMQConnectionFactory("tcp://localhost:61616");
>         Connection connection = null;
>         Session session = null;
>         MessageProducer producer = null;
>         TemporaryQueue temporaryQueue = null;
>         try {
>             connection = factory.createConnection();
>             connection.start();
>             // The session has to be transacted for the second "ghost" 
> message to appear (see below).
>             session = connection.createSession(true, 
> Session.SESSION_TRANSACTED);
>             // And the publication has to be on a temporary queue (if the 
> temporary queue is created by another process, the second "ghost" message 
> still appears).
>             temporaryQueue = session.createTemporaryQueue();
>             producer = session.createProducer(temporaryQueue);
>             final TextMessage textMessage = session.createTextMessage();
>             textMessage.setText("GhostMessageDemo@" + new 
> SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss,SSSZ").format(new Date()));
>             producer.send(textMessage);
>             // Here, in ActiveMQ 5.13.1 and 5.12.2, the message was sent but 
> cannot be browsed or consumed. It can however be seen in the JMX console with:
>             // - EnqueueCount, that was increased by one;
>             // - MemoryUsageByteCount (by sending huge messages of different 
> size to ensure that it is indeed the real message).
>             // In ActiveMQ 5.10.2 (and 5.4.1), it is not sent (even though 
> SocketOutputStream.socketWrite is still called through TcpFormat.oneway?).
>             session.commit();
>             // Here, in ActiveMQ 5.13.1, a "ghost" message was sent 
> (EnqueueCount has increased by one again) and the real message is visible and 
> can be consumed.
>             // If rollback is called instead, the real message stays (and 
> cannot be consumed since the "ghost" message is not sent).
>         } finally {
>             if (producer != null)
>                 producer.close();
>             if (temporaryQueue != null)
>                 // Here, if there was a consumer on the queue, it would have 
> consumed the real message, leaving the "ghost" message that lead to the 
> broker warning.
>                 temporaryQueue.delete();
>             if (session != null)
>                 session.close();
>             if (connection != null) {
>                 connection.stop();
>                 connection.close();
>             }
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to