Created
September 6, 2016 10:14
-
-
Save dborovikov/e0d95d4354dfc2e6c4f82d16a0644497 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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®ion=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