7 Ağustos 2020 Cuma

Camel RouteBuilder Sınıfı

Giriş
Şus satırı dahil ederiz
import org.apache.camel.builder.RouteBuilder;
configure metodu
Route kuralları DSL ile yazılır. from ve to ile hangi Component'ten hangi Component'e bilgi akacağı belirtilir. 

Açıklaması şöyle. DSL farklı diller ile yazılabilir. Sanırım en kolayı Fluent API
Apache Camel offers various DSLs, such as Java-based Fluent API, Spring, or Blueprint XML Configuration files, and a Scala DSL. 
- Spring XML DSL is based on the Spring framework and uses XML configuration. 
- Java DSL has the best IDE support.  
- Groovy and Scala DSLs are similar to the Java DSL; in addition, they offer the typical features of modern JVM languages, such as concise code or closures.
Örnek - JMS
Şöyle yaparız
@Component
public class SomeRoute extends RouteBuilder {
  @Override
  public void configure() throws Exception {
    from("jms:{{queue.name}}")
    .process("xmlToJsonProcessor")
    .to("kafka:{{topic}}?brokers={{spring.kafka.bootstrap-servers}}&
      securityProtocol={{spring.kafka.properties.security.protocol}}&
      saslMechanism={{spring.kafka.properties.sasl.mechanism}}&
      saslJaasConfig={{spring.kafka.properties.sasl.jaas.config}}");
  }   
}
Eğer consumer sayısını artırmak istersek şöyle yaparız
@Component
public class SomeRoute extends RouteBuilder {
  @Override
  public void configure() throws Exception {
    from("jms:{{queue.name}}?concurrentConsumers=10")
    .process("xmlToJsonProcessor")
    .to("...");
   }   
}
Örnek - netty
Şöyle yaparız
from("netty:tcp://localhost:9011?textline=true&encoding=ISO-8859-1&sync=true")
.process(new Processor() {
  @Override
  public void process(Exchange exchange) throws InterruptedException {
    String data=exchange.getIn().getBody(String.class);
    ...
  }
})
.to("log:?level=INFO&showBody=true");
Örnek - timer singleshot
Şöyle yaparız
from("timer://runOnce?repeatCount=1&delay=5000")
  .serviceCall("myService");
Örnek - timer periodic
Şöyle yaparız
from("timer://foo?period=100")
.to("direct:bar");
Örnek - timer periodic
Şöyle yaparız
from("timer:theTimer?period=10s")
.log("Timer Invoked . . . ")
.pollEnrich("file:data/input?delete=true&readLock=none")
.log("BODY = [ ${body} ] " )
.to("file:data/output");

Hiç yorum yok:

Yorum Gönder