Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 70208 invoked from network); 23 Apr 2010 13:41:08 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Apr 2010 13:41:08 -0000 Received: (qmail 97031 invoked by uid 500); 23 Apr 2010 13:41:08 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 97007 invoked by uid 500); 23 Apr 2010 13:41:08 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 97000 invoked by uid 99); 23 Apr 2010 13:41:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Apr 2010 13:41:08 +0000 X-ASF-Spam-Status: No, hits=-1167.8 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Apr 2010 13:41:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4371323889B8; Fri, 23 Apr 2010 13:40:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r937289 - in /activemq/trunk/activemq-camel/src: main/java/org/apache/activemq/camel/converter/ test/java/org/apache/activemq/camel/ test/resources/org/apache/activemq/camel/ Date: Fri, 23 Apr 2010 13:40:25 -0000 To: commits@activemq.apache.org From: gtully@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100423134025.4371323889B8@eris.apache.org> Author: gtully Date: Fri Apr 23 13:40:24 2010 New Revision: 937289 URL: http://svn.apache.org/viewvc?rev=937289&view=rev Log: provide test that validates camel loopback redelivery alternative to blocking client side redelivery, resolve: https://issues.apache.org/activemq/browse/AMQ-2710 Added: activemq/trunk/activemq-camel/src/main/java/org/apache/activemq/camel/converter/IdentityMessageReuseConverter.java (with props) activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/CamelRedeliveryTest.java (with props) activemq/trunk/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelRedeliveryTest-context.xml (with props) Added: activemq/trunk/activemq-camel/src/main/java/org/apache/activemq/camel/converter/IdentityMessageReuseConverter.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-camel/src/main/java/org/apache/activemq/camel/converter/IdentityMessageReuseConverter.java?rev=937289&view=auto ============================================================================== --- activemq/trunk/activemq-camel/src/main/java/org/apache/activemq/camel/converter/IdentityMessageReuseConverter.java (added) +++ activemq/trunk/activemq-camel/src/main/java/org/apache/activemq/camel/converter/IdentityMessageReuseConverter.java Fri Apr 23 13:40:24 2010 @@ -0,0 +1,56 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.camel.converter; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; + +import org.apache.activemq.command.ActiveMQMessage; +import org.springframework.jms.support.converter.MessageConversionException; +import org.springframework.jms.support.converter.MessageConverter; +import org.springframework.util.ObjectUtils; + +/** + * Identity conversion, return the original ActiveMQMessage as is, useful when camel does message + * redelivery routing. ReadOnlyPropertes flag inverted to allow + * additional properties to be appended or existing properties to be modified + */ +public class IdentityMessageReuseConverter implements MessageConverter { + + /* (non-Javadoc) + * @see org.springframework.jms.support.converter.MessageConverter#fromMessage(javax.jms.Message) + */ + public Object fromMessage(Message message) throws JMSException, MessageConversionException { + return message; + } + + /* (non-Javadoc) + * @see org.springframework.jms.support.converter.MessageConverter#toMessage(java.lang.Object, javax.jms.Session) + */ + public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { + if (object instanceof ActiveMQMessage) { + // allow setting additional properties + ((ActiveMQMessage)object).setReadOnlyProperties(false); + return (Message)object; + } else { + throw new MessageConversionException("Cannot reuse object of type [" + + ObjectUtils.nullSafeClassName(object) + "] as ActiveMQMessage message. Message must already be an ActiveMQMessage."); + } + } +} Propchange: activemq/trunk/activemq-camel/src/main/java/org/apache/activemq/camel/converter/IdentityMessageReuseConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/trunk/activemq-camel/src/main/java/org/apache/activemq/camel/converter/IdentityMessageReuseConverter.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/CamelRedeliveryTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/CamelRedeliveryTest.java?rev=937289&view=auto ============================================================================== --- activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/CamelRedeliveryTest.java (added) +++ activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/CamelRedeliveryTest.java Fri Apr 23 13:40:24 2010 @@ -0,0 +1,86 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.camel; + +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.activemq.ActiveMQConnection; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.RedeliveryPolicy; +import org.apache.activemq.command.ActiveMQQueue; +import org.apache.camel.CamelContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests; + +/** + * @version $Revision$ + */ +@ContextConfiguration +public class CamelRedeliveryTest extends AbstractJUnit38SpringContextTests { + private static final transient Log LOG = LogFactory.getLog(CamelRedeliveryTest.class); + + @Autowired + protected CamelContext camelContext; + + public void testRedeliveryViaCamel() throws Exception { + + + ActiveMQConnectionFactory factory = applicationContext.getBean("connectionFactory", ActiveMQConnectionFactory.class); + ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection(); + + // send message to dlq immediately + RedeliveryPolicy policy = connection.getRedeliveryPolicy(); + policy.setMaximumRedeliveries(0); + connection.start(); + + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + ActiveMQQueue destination = new ActiveMQQueue("camelRedeliveryQ"); + MessageProducer producer = session.createProducer(destination); + + MessageConsumer consumer = session.createConsumer(destination); + // Send the messages + producer.send(session.createTextMessage("1st")); + session.commit(); + LOG.info("sent 1st message"); + + TextMessage m; + m = (TextMessage)consumer.receive(1000); + assertNotNull(m); + assertEquals("1st", m.getText()); + session.rollback(); + + LOG.info("received and rolledback 1st message: " + m); + m = (TextMessage)consumer.receive(1); + assertNull("no immediate redelivery", m); + + m = (TextMessage)consumer.receive(20000); + LOG.info("received redelivery on second wait attempt, message: " + m); + + assertNotNull("got redelivery on second attempt", m); + assertEquals("text matches original", "1st", m.getText()); + + // came from camel + assertTrue("redelivery marker header set, so came from camel", m.getBooleanProperty("CamelRedeliveryMarker")); + } +} \ No newline at end of file Propchange: activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/CamelRedeliveryTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/trunk/activemq-camel/src/test/java/org/apache/activemq/camel/CamelRedeliveryTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: activemq/trunk/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelRedeliveryTest-context.xml URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelRedeliveryTest-context.xml?rev=937289&view=auto ============================================================================== --- activemq/trunk/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelRedeliveryTest-context.xml (added) +++ activemq/trunk/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelRedeliveryTest-context.xml Fri Apr 23 13:40:24 2010 @@ -0,0 +1,44 @@ + + + + + + + + + true + + 1000 + + + + + + + + + + + + Propchange: activemq/trunk/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelRedeliveryTest-context.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/trunk/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelRedeliveryTest-context.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: activemq/trunk/activemq-camel/src/test/resources/org/apache/activemq/camel/CamelRedeliveryTest-context.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml