use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class TransformerTests method transformWithHeader.
@Test
public void transformWithHeader() {
QueueChannel replyChannel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload("Foo").setReplyChannel(replyChannel).build();
this.pojoTransformFlowInput.send(message);
Message<?> receive = replyChannel.receive(10000);
assertNotNull(receive);
assertEquals("FooBar", receive.getPayload());
try {
this.pojoTransformFlowInput.send(message);
fail("MessageRejectedException expected");
} catch (Exception e) {
assertThat(e, instanceOf(MessageRejectedException.class));
assertThat(e.getMessage(), containsString("IdempotentReceiver"));
assertThat(e.getMessage(), containsString("rejected duplicate Message"));
}
assertNotNull(this.idempotentDiscardChannel.receive(10000));
assertNotNull(this.adviceChannel.receive(10000));
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class RoundRobinDispatcherConcurrentTests method noHandlerSkipUnderConcurrentFailureWithFailover.
@Test
public void noHandlerSkipUnderConcurrentFailureWithFailover() throws Exception {
dispatcher.addHandler(handler1);
dispatcher.addHandler(handler2);
doThrow(new MessageRejectedException(message, null)).when(handler1).handleMessage(message);
final CountDownLatch start = new CountDownLatch(1);
final CountDownLatch allDone = new CountDownLatch(TOTAL_EXECUTIONS);
final Message<?> message = this.message;
final AtomicBoolean failed = new AtomicBoolean(false);
Runnable messageSenderTask = new Runnable() {
@Override
public void run() {
try {
start.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
if (!dispatcher.dispatch(message)) {
failed.set(true);
} else {
allDone.countDown();
}
}
};
for (int i = 0; i < TOTAL_EXECUTIONS; i++) {
executor.execute(messageSenderTask);
}
start.countDown();
allDone.await(5000, TimeUnit.MILLISECONDS);
assertFalse("not all messages were accepted", failed.get());
verify(handler1, times(TOTAL_EXECUTIONS / 2)).handleMessage(message);
verify(handler2, times(TOTAL_EXECUTIONS)).handleMessage(message);
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class IdempotentReceiverInterceptor method doInvoke.
@Override
protected Object doInvoke(MethodInvocation invocation, Message<?> message) throws Throwable {
boolean accept = this.messageSelector.accept(message);
if (!accept) {
boolean discarded = false;
MessageChannel theDiscardChannel = obtainDiscardChannel();
if (theDiscardChannel != null) {
this.messagingTemplate.send(theDiscardChannel, message);
discarded = true;
}
if (this.throwExceptionOnRejection) {
throw new MessageRejectedException(message, "IdempotentReceiver '" + this + "' rejected duplicate Message: " + message);
}
if (!discarded) {
invocation.getArguments()[0] = getMessageBuilderFactory().fromMessage(message).setHeader(IntegrationMessageHeaderAccessor.DUPLICATE_MESSAGE, true).build();
} else {
return null;
}
}
return invocation.proceed();
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method noFailoverLoadBalancing.
@Test
public void noFailoverLoadBalancing() {
DirectChannel channel = (DirectChannel) ac.getBean("loadBalancerNoFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy());
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
dispatcher.addHandler(handlerC);
InOrder inOrder = inOrder(handlerA, handlerB, handlerC);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerA).handleMessage(message);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerB).handleMessage(message);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerC).handleMessage(message);
verify(handlerA, times(1)).handleMessage(message);
verify(handlerB, times(1)).handleMessage(message);
verify(handlerC, times(1)).handleMessage(message);
}
use of org.springframework.integration.MessageRejectedException in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method failoverNoLoadBalancing.
@Test
public void failoverNoLoadBalancing() {
DirectChannel channel = (DirectChannel) ac.getBean("noLoadBalancerFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
InOrder inOrder = inOrder(handlerA, handlerB);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerA).handleMessage(message);
inOrder.verify(handlerB).handleMessage(message);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerA).handleMessage(message);
inOrder.verify(handlerB).handleMessage(message);
verify(handlerA, times(2)).handleMessage(message);
verify(handlerB, times(2)).handleMessage(message);
}
Aggregations