7 Ağustos 2020 Cuma

Camel DefaultCamelContext Sınıfı

Giriş
Şu satırı dahil ederiz
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
Açıklaması şöyle.
Camel context provides the runtime environment for the whole Apache Camel application. Usually, we will create one context per application and all Camel routes will be executed within the context.
addComponent metodu

AHC WebSocket Component 
Açıklaması şöyle.
The AHC-WS component provides Websocket based endpoints for a client communicating with external servers over Websocket (as a client opening a websocket connection to an external server).

WebSocket Component
Açıklaması şöyle.
Jetty WebSocket Component (and Atmosphere WebSocket component) is intended to expose new WebSocket server. If you need to connect as client to remote WebSocket server, you should use AHC Websocket component

addRoutes metodu
Şöyle yaparız
public static void main(String[] args) {

  RouteBuilder routeBuilder = ...
  CamelContext ctx = new DefaultCamelContext();

  try {
    ctx.addRoutes(routeBuilder);
    ctx.start();
    Thread.sleep(10 * 60 * 1000);
    ctx.stop();
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
start metodu
Açıklaması şöyle. Bu metod çağrısı non-blocking olduğu için JVM'in exit etmemesine dikkat etmek gerekir.
Camel context implements a Java Service lifecycle interface so it has  start()  and  stop()  methods. In addition to that, it implements  suspend()  and  resume()  methods so it is convenient and easy to manage the context lifecycle. 
Şöyle yaparız.
context.start();
stop metodu
Açıklaması şöyle. Aslında shutdown gibi düşünülebilir.
The operations is paired: start/stop and suspend/resume.

Stop is performing a Graceful shutdown which means all its internal state, cache, etc is cleared. And the routes is being stopped in a graceful manner to ensure messages are given time to complete. If you start a CamelContext after a stop, then its performing a cold start, recreating all the state, cache etc. again.
Şöyle yaparız.
context.stop();



Hiç yorum yok:

Yorum Gönder