You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by cineva <an...@yahoo.com> on 2013/07/05 09:53:41 UTC

ActiveMQ-CPP - Rollback function returns but the server isn't done rollbacking

The following program depends on the time it takes to rollback the session.
If I run it in a debugger line by line it returns the correct behavior
("Another Test message" in "testqueue" queue) but if I let it run I get
"Test message". Is this something by design (are only asynchronous rollbacks
supported?) or is it a bug? This test program will always return "Another
Test message" if I increase to time to receive the message because it has
time to get the message because the rollback is finished but it doesn't
solve the issue. I don't know if this is a server or client issue.

	ActiveMQConnectionFactory factory("tcp://localhost:61616");
	cms::Connection* connection(factory.createConnection());
	connection->start();

	cms::Session* session =
connection->createSession(cms::Session::SESSION_TRANSACTED);
	cms::Queue* queue = session->createQueue("testqueue");
	cms::MessageProducer* producer(session->createProducer(queue));
	cms::MessageConsumer* consumer = session->createConsumer(queue);

	cms::Message* message = session->createTextMessage("Test message");
	producer->send(message);

	session->commit();

	for ( int i=1; i<=4; i++ )
	{
		cms::Message* receivedMessage = consumer->receive(500);
		if ( receivedMessage && receivedMessage->getIntProperty(
"JMSXDeliveryCount" ) == 3 )
		{
			cms::Message* newMessage = session->createTextMessage("Another Test
message");
			producer->send(newMessage);
			session->commit();
		}
		else
			session->rollback();
	}



--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-CPP-Rollback-function-returns-but-the-server-isn-t-done-rollbacking-tp4668896.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ-CPP - Rollback function returns but the server isn't done rollbacking

Posted by cineva <an...@yahoo.com>.
Thanks, I got it to work.



--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-CPP-Rollback-function-returns-but-the-server-isn-t-done-rollbacking-tp4668896p4668925.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ-CPP - Rollback function returns but the server isn't done rollbacking

Posted by Timothy Bish <ta...@gmail.com>.
On 07/05/2013 09:52 AM, cineva wrote:
> The test was a short version of what I'm trying to do. The following code
> depends on the time it takes from the rollback to the second receive. If I
> wait a while after the rollback the output is "received received" else it's
> "received not received". Is this how ActiveMQ-CPP and ActiveMQ are supposed
> to behave?
>
> 	if ( consumer->receive(500) )
> 		cout << "received ";
> 	else
> 		cout << "not received ";
> 	session->rollback();
> 	// Sleep a while
> 	if ( consumer->receive(500) )
> 		cout << "received ";
> 	else
> 		cout << "not received ";
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-CPP-Rollback-function-returns-but-the-server-isn-t-done-rollbacking-tp4668896p4668923.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
The redelivery policy defines the delays for initial redelivery delay 
and continued delays for additional rollbacks along with max 
redeliveries so you need to tune the policy to define what behavior you 
want.

-- 
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/

www.camelone.org : The open source integration conference:


Re: ActiveMQ-CPP - Rollback function returns but the server isn't done rollbacking

Posted by cineva <an...@yahoo.com>.
The test was a short version of what I'm trying to do. The following code
depends on the time it takes from the rollback to the second receive. If I
wait a while after the rollback the output is "received received" else it's
"received not received". Is this how ActiveMQ-CPP and ActiveMQ are supposed
to behave?

	if ( consumer->receive(500) )
		cout << "received ";
	else
		cout << "not received ";
	session->rollback();
	// Sleep a while
	if ( consumer->receive(500) )
		cout << "received ";
	else
		cout << "not received ";



--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-CPP-Rollback-function-returns-but-the-server-isn-t-done-rollbacking-tp4668896p4668923.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ-CPP - Rollback function returns but the server isn't done rollbacking

Posted by Timothy Bish <ta...@gmail.com>.
On 07/05/2013 08:22 AM, cineva wrote:
> My problem is that I expected to find "Another Test message" in the queue and
> not "Test message". If for example I insert a sleep after
> session->rollback(); the program runs as expected. Why does
> session->rollback(); return but the session isn't exactly rollbacked? Is
> this the intended behavior?
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-CPP-Rollback-function-returns-but-the-server-isn-t-done-rollbacking-tp4668896p4668913.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
I can't really say since the test code doesn't make much sense to me.

-- 
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/

www.camelone.org : The open source integration conference:


Re: ActiveMQ-CPP - Rollback function returns but the server isn't done rollbacking

Posted by cineva <an...@yahoo.com>.
My problem is that I expected to find "Another Test message" in the queue and
not "Test message". If for example I insert a sleep after
session->rollback(); the program runs as expected. Why does
session->rollback(); return but the session isn't exactly rollbacked? Is
this the intended behavior? 



--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-CPP-Rollback-function-returns-but-the-server-isn-t-done-rollbacking-tp4668896p4668913.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ-CPP - Rollback function returns but the server isn't done rollbacking

Posted by Timothy Bish <ta...@gmail.com>.
Not entirely sure what you are trying to accomplish here.  You always 
commit the messages so they are going to get sent, and if you use the 
default redelivery policy the messages that a consumer receives but 
rolls back will get redelivered.

On 07/05/2013 03:53 AM, cineva wrote:
> The following program depends on the time it takes to rollback the session.
> If I run it in a debugger line by line it returns the correct behavior
> ("Another Test message" in "testqueue" queue) but if I let it run I get
> "Test message". Is this something by design (are only asynchronous rollbacks
> supported?) or is it a bug? This test program will always return "Another
> Test message" if I increase to time to receive the message because it has
> time to get the message because the rollback is finished but it doesn't
> solve the issue. I don't know if this is a server or client issue.
>
> 	ActiveMQConnectionFactory factory("tcp://localhost:61616");
> 	cms::Connection* connection(factory.createConnection());
> 	connection->start();
>
> 	cms::Session* session =
> connection->createSession(cms::Session::SESSION_TRANSACTED);
> 	cms::Queue* queue = session->createQueue("testqueue");
> 	cms::MessageProducer* producer(session->createProducer(queue));
> 	cms::MessageConsumer* consumer = session->createConsumer(queue);
>
> 	cms::Message* message = session->createTextMessage("Test message");
> 	producer->send(message);
>
> 	session->commit();
>
> 	for ( int i=1; i<=4; i++ )
> 	{
> 		cms::Message* receivedMessage = consumer->receive(500);
> 		if ( receivedMessage && receivedMessage->getIntProperty(
> "JMSXDeliveryCount" ) == 3 )
> 		{
> 			cms::Message* newMessage = session->createTextMessage("Another Test
> message");
> 			producer->send(newMessage);
> 			session->commit();
> 		}
> 		else
> 			session->rollback();
> 	}
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-CPP-Rollback-function-returns-but-the-server-isn-t-done-rollbacking-tp4668896.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>


-- 
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/

www.camelone.org : The open source integration conference: