Added support for 'apply-sequence' on <publish-subscribe-channel/>. The BroadcastingDispatcher has the 'applySequence' property (INT-321).
This commit is contained in:
@@ -41,6 +41,7 @@ public class PublishSubscribeChannelParser extends AbstractChannelParser {
|
||||
if (StringUtils.hasText(taskExecutorRef)) {
|
||||
builder.addConstructorArgReference(taskExecutorRef);
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="channelType">
|
||||
<xsd:attribute name="task-executor" type="xsd:string"/>
|
||||
<xsd:attribute name="apply-sequence" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.dispatcher;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
|
||||
/**
|
||||
@@ -30,18 +31,37 @@ import org.springframework.integration.message.MessageTarget;
|
||||
*/
|
||||
public class BroadcastingDispatcher extends AbstractDispatcher {
|
||||
|
||||
public boolean send(final Message<?> message) {
|
||||
private volatile boolean applySequence;
|
||||
|
||||
|
||||
/**
|
||||
* Specify whether to apply sequence numbers to the messages
|
||||
* prior to sending to the targets. By default, sequence
|
||||
* numbers will <em>not</em> be applied
|
||||
*/
|
||||
public void setApplySequence(boolean applySequence) {
|
||||
this.applySequence = applySequence;
|
||||
}
|
||||
|
||||
public boolean send(Message<?> message) {
|
||||
int sequenceNumber = 1;
|
||||
int sequenceSize = this.targets.size();
|
||||
for (final MessageTarget target : this.targets) {
|
||||
final Message<?> messageToSend = (!this.applySequence) ? message
|
||||
: MessageBuilder.fromMessage(message)
|
||||
.setSequenceNumber(sequenceNumber++)
|
||||
.setSequenceSize(sequenceSize)
|
||||
.build();
|
||||
TaskExecutor executor = this.getTaskExecutor();
|
||||
if (executor != null) {
|
||||
executor.execute(new Runnable() {
|
||||
public void run() {
|
||||
sendMessageToTarget(message, target);
|
||||
sendMessageToTarget(messageToSend, target);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.sendMessageToTarget(message, target);
|
||||
this.sendMessageToTarget(messageToSend, target);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -33,9 +33,6 @@ public class PublishSubscribeChannel extends AbstractMessageChannel implements S
|
||||
private final BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
|
||||
|
||||
|
||||
public PublishSubscribeChannel() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a PublishSubscribeChannel that will use a {@link TaskExecutor}
|
||||
* to publish its Messages.
|
||||
@@ -46,6 +43,13 @@ public class PublishSubscribeChannel extends AbstractMessageChannel implements S
|
||||
}
|
||||
}
|
||||
|
||||
public PublishSubscribeChannel() {
|
||||
}
|
||||
|
||||
|
||||
public void setApplySequence(boolean applySequence) {
|
||||
this.dispatcher.setApplySequence(applySequence);
|
||||
}
|
||||
|
||||
public boolean subscribe(MessageTarget target) {
|
||||
return this.dispatcher.addTarget(target);
|
||||
|
||||
Reference in New Issue
Block a user