git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1183143 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-10-13 22:28:47 +00:00
parent 4acd13243a
commit 88f60580e3
3 changed files with 151 additions and 95 deletions

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.camel.component;
import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
@ -67,6 +69,36 @@ public class ActiveMQRouteTest extends CamelTestSupport {
return camelContext;
}
@Test
public void testInvalidDestinationOptionOnConsumer() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(0);
assertMockEndpointsSatisfied(1, TimeUnit.SECONDS);
try {
new RouteBuilder() {
public void configure() throws Exception {
from("activemq:queue:foo?destination.consumer.exclusive=true&destination.consumer.unknown=foo")
.to("mock:result");
}
};
} catch (Exception e) {
fail("Should not have accepted bad destination options.");
}
}
@Test
public void testInvalidDestinationOptionOnProducer() throws Exception {
try {
new RouteBuilder() {
public void configure() throws Exception {
from("activemq:queue:foo")
.to("activemq:queue:bar?destination.producer.exclusive=true");
}
};
} catch (Exception e) {
fail("Should not have accepted bad destination options.");
}
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {

View File

@ -225,6 +225,15 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
if (dest.getOptions() != null) {
Map<String, String> options = new HashMap<String, String>(dest.getOptions());
IntrospectionSupport.setProperties(this.info, options, "consumer.");
if (options.size() > 0) {
String msg = "There are " + options.size()
+ " consumer options that couldn't be set on the consumer."
+ " Check the options are spelled correctly."
+ " Unknown parameters=[" + options + "]."
+ " This consumer cannot be started.";
LOG.warn(msg);
throw new ConfigurationException(msg);
}
}
this.info.setDestination(dest);
@ -459,11 +468,11 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
if (timeout > 0 && !unconsumedMessages.isClosed()) {
timeout = Math.max(deadline - System.currentTimeMillis(), 0);
} else {
if (failureError != null) {
throw JMSExceptionSupport.create(failureError);
} else {
return null;
}
if (failureError != null) {
throw JMSExceptionSupport.create(failureError);
} else {
return null;
}
}
} else if (md.getMessage() == null) {
return null;
@ -524,7 +533,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
private ActiveMQMessage createActiveMQMessage(final MessageDispatch md) throws JMSException {
ActiveMQMessage m = (ActiveMQMessage)md.getMessage().copy();
if (m.getDataStructureType()==CommandTypes.ACTIVEMQ_BLOB_MESSAGE) {
((ActiveMQBlobMessage)m).setBlobDownloader(new BlobDownloader(session.getBlobTransferPolicy()));
((ActiveMQBlobMessage)m).setBlobDownloader(new BlobDownloader(session.getBlobTransferPolicy()));
}
if (transformer != null) {
Message transformedMessage = transformer.consumerTransform(session, this, m);
@ -706,11 +715,11 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
if (ack != null) {
deliveredMessages.clear();
ackCounter = 0;
} else {
ack = pendingAck;
pendingAck = null;
}
}
} else {
ack = pendingAck;
pendingAck = null;
}
}
} else if (pendingAck != null && pendingAck.isStandardAck()) {
ack = pendingAck;
pendingAck = null;
@ -874,13 +883,13 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
if (optimizeAcknowledge) {
ackCounter++;
if (ackCounter >= (info.getPrefetchSize() * .65) || (optimizeAcknowledgeTimeOut > 0 && System.currentTimeMillis() >= (optimizeAckTimestamp + optimizeAcknowledgeTimeOut))) {
MessageAck ack = makeAckForAllDeliveredMessages(MessageAck.STANDARD_ACK_TYPE);
if (ack != null) {
deliveredMessages.clear();
ackCounter = 0;
session.sendAck(ack);
optimizeAckTimestamp = System.currentTimeMillis();
}
MessageAck ack = makeAckForAllDeliveredMessages(MessageAck.STANDARD_ACK_TYPE);
if (ack != null) {
deliveredMessages.clear();
ackCounter = 0;
session.sendAck(ack);
optimizeAckTimestamp = System.currentTimeMillis();
}
}
} else {
MessageAck ack = makeAckForAllDeliveredMessages(MessageAck.STANDARD_ACK_TYPE);
@ -917,17 +926,17 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
* @param type Ack-Type (i.e. MessageAck.STANDARD_ACK_TYPE)
* @return <code>null</code> if nothing to ack.
*/
private MessageAck makeAckForAllDeliveredMessages(byte type) {
synchronized (deliveredMessages) {
if (deliveredMessages.isEmpty())
return null;
private MessageAck makeAckForAllDeliveredMessages(byte type) {
synchronized (deliveredMessages) {
if (deliveredMessages.isEmpty())
return null;
MessageDispatch md = deliveredMessages.getFirst();
MessageAck ack = new MessageAck(md, type, deliveredMessages.size());
ack.setFirstMessageId(deliveredMessages.getLast().getMessage().getMessageId());
return ack;
}
}
MessageDispatch md = deliveredMessages.getFirst();
MessageAck ack = new MessageAck(md, type, deliveredMessages.size());
ack.setFirstMessageId(deliveredMessages.getLast().getMessage().getMessageId());
return ack;
}
}
private void ackLater(MessageDispatch md, byte ackType) throws JMSException {
@ -1016,7 +1025,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
// Acknowledge all messages so far.
MessageAck ack = makeAckForAllDeliveredMessages(MessageAck.STANDARD_ACK_TYPE);
if (ack == null)
return; // no msgs
return; // no msgs
if (session.getTransacted()) {
rollbackOnFailedRecoveryRedelivery();
@ -1154,7 +1163,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
MessageAck ack = new MessageAck(lastMd, MessageAck.POSION_ACK_TYPE, deliveredMessages.size());
ack.setPoisonCause(lastMd.getRollbackCause());
ack.setFirstMessageId(firstMsgId);
ack.setFirstMessageId(firstMsgId);
session.sendAck(ack,true);
// Adjust the window size.
additionalWindowSize = Math.max(0, additionalWindowSize - deliveredMessages.size());
@ -1410,11 +1419,11 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
return lastDeliveredSequenceId;
}
public IOException getFailureError() {
return failureError;
}
public IOException getFailureError() {
return failureError;
}
public void setFailureError(IOException failureError) {
this.failureError = failureError;
}
public void setFailureError(IOException failureError) {
this.failureError = failureError;
}
}

View File

@ -33,6 +33,8 @@ import org.apache.activemq.management.StatsCapable;
import org.apache.activemq.management.StatsImpl;
import org.apache.activemq.usage.MemoryUsage;
import org.apache.activemq.util.IntrospectionSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A client uses a <CODE>MessageProducer</CODE> object to send messages to a
@ -68,6 +70,8 @@ import org.apache.activemq.util.IntrospectionSupport;
*/
public class ActiveMQMessageProducer extends ActiveMQMessageProducerSupport implements StatsCapable, Disposable {
private static final Logger LOG = LoggerFactory.getLogger(ActiveMQMessageProducer.class);
protected ProducerInfo info;
protected boolean closed;
@ -81,10 +85,21 @@ public class ActiveMQMessageProducer extends ActiveMQMessageProducerSupport impl
super(session);
this.info = new ProducerInfo(producerId);
this.info.setWindowSize(session.connection.getProducerWindowSize());
// Allows the options on the destination to configure the producerInfo
if (destination != null && destination.getOptions() != null) {
Map<String, String> options = new HashMap<String, String>(destination.getOptions());
IntrospectionSupport.setProperties(this.info, options, "producer.");
if (options.size() > 0) {
String msg = "There are " + options.size()
+ " producer options that couldn't be set on the producer."
+ " Check the options are spelled correctly."
+ " Unknown parameters=[" + options + "]."
+ " This producer cannot be started.";
LOG.warn(msg);
throw new ConfigurationException(msg);
}
}
this.info.setDestination(destination);
// Enable producer window flow control if protocol > 3 and the window