Skip to content

Instantly share code, notes, and snippets.

@dborovikov
Created September 6, 2016 10:14
Show Gist options
  • Select an option

  • Save dborovikov/e0d95d4354dfc2e6c4f82d16a0644497 to your computer and use it in GitHub Desktop.

Select an option

Save dborovikov/e0d95d4354dfc2e6c4f82d16a0644497 to your computer and use it in GitHub Desktop.
import com.amazonaws.services.sqs.AmazonSQSClient;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.SimpleRegistry;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
public class CamelSQSDemo {
public static void main(String[] args) throws Exception {
SimpleRegistry registry = new SimpleRegistry();
registry.put("sqsClient", new AmazonSQSClient());
CamelContext context = new DefaultCamelContext(registry);
AtomicReference<Long> lastTS = new AtomicReference<>(System.currentTimeMillis());
AtomicInteger counter = new AtomicInteger();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("aws-sqs://znap-cs-ci?amazonSQSClient=#sqsClient&region=eu-central-1&queueOwnerAWSAccountId=490436819829&maxMessagesPerPoll=10&deleteAfterRead=false")
.process(e -> {
long now = System.currentTimeMillis();
if (now - lastTS.get() >= 1000) {
lastTS.set(now);
System.out.println(counter.getAndSet(0));
}
counter.incrementAndGet();
String timeString = DateTimeFormatter.ofPattern("ss").format(ZonedDateTime.now());
e.getOut().setBody("ARTICLE " + timeString);
})
.to("stream:out");
}
});
context.start();
Thread.sleep(Long.MAX_VALUE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment