Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from("rabbitmq://hostname[:port]/myqueue_high")
- .setHeader("priority", constant(9))
- .to("direct:messageProcessing");
- from("rabbitmq://hostname[:port]/myqueue_medium")
- .setHeader("priority", constant(5))
- .to("direct:messageProcessing");
- from("rabbitmq://hostname[:port]/myqueue_low")
- .setHeader("priority", constant(1))
- .to("direct:messageProcessing");
- // sort by priority by allowing duplicates (message can have same priority)
- // and use reverse ordering so 9 is first output (most important), and 0 is last
- // (of course we could have set the priority the other way around, but this way
- // we keep align with the JMS specification...)
- // use batch mode and fire every 3th second
- from("direct:messageProcessing")
- .resequence(header("priority")).batch().timeout(3000).allowDuplicates().reverse()
- .to("mock:result");
- final PriorityBlockingQueueFactory<Exchange> priorityQueueFactory = new PriorityBlockingQueueFactory<Exchange>();
- priorityQueueFactory.setComparator(new Comparator<Exchange>() {
- @Override
- public int compare(final Exchange exchange1, final Exchange exchange2) {
- final Integer prio1 = (Integer) exchange1.getIn().getHeader("priority");
- final Integer prio2 = (Integer) exchange2.getIn().getHeader("priority");
- return -prio1.compareTo(prio2); // 9 has higher priority then 0
- }
- });
- final SimpleRegistry registry = new SimpleRegistry();
- registry.put("priorityQueueFactory", priorityQueueFactory);
- final ModelCamelContext context = new DefaultCamelContext(registry);
- // configure and start your context here...
- from("rabbitmq://hostname[:port]/myqueue_high")
- .setHeader("priority", constant(9))
- .to("seda:priority?queueFactory=#priorityQueueFactory"); // reference queue in registry
- from("rabbitmq://hostname[:port]/myqueue_medium")
- .setHeader("priority", constant(5))
- .to("seda:priority?queueFactory=#priorityQueueFactory");
- from("rabbitmq://hostname[:port]/myqueue_low")
- .setHeader("priority", constant(1))
- .to("seda:priority?queueFactory=#priorityQueueFactory");
- from("seda:priority")
- .to("direct:messageProcessing");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement