Created
April 8, 2016 08:40
-
-
Save lburgazzoli/e000eef4ab41be09e40d142bdd527285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.slf4j', module='slf4j-simple', version='1.7.14') | |
@Grab(group='org.apache.camel', module='camel-core', version='2.16.0') | |
@Grab(group='org.apache.camel', module='camel-infinispan', version='2.16.0') | |
import org.apache.camel.impl.DefaultCamelContext | |
import org.apache.camel.builder.RouteBuilder | |
import org.apache.camel.component.infinispan.processor.idempotent.InfinispanIdempotentRepository | |
import org.infinispan.client.hotrod.RemoteCacheManager | |
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder | |
def ctx = new DefaultCamelContext() | |
ctx.addRoutes(new RouteBuilder() { | |
void configure() { | |
from("direct:start") | |
.idempotentConsumer( | |
header("MessageID"), | |
new InfinispanIdempotentRepository( | |
new RemoteCacheManager( | |
new ConfigurationBuilder() | |
.addServers("localhost") | |
.forceReturnValues(true) | |
.build(), | |
true | |
), | |
"idempotent" | |
) | |
) | |
.skipDuplicate(true) | |
.to("log:camel-groovy?level=INFO&showAll=true&multiline=true"); | |
} | |
}) | |
ctx.start() | |
def messageid = UUID.randomUUID().toString() | |
def template = ctx.createProducerTemplate() | |
template.sendBodyAndHeaders("direct:start", "message-1", [ 'MessageID': messageid ]) | |
template.sendBodyAndHeaders("direct:start", "message-2", [ 'MessageID': messageid ]) | |
Thread.sleep(5000) | |
ctx.stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment