How to use RoutePolicy to prevent a route from starting

2023-08-28 Thread Han Yainsun
Hi Camel Community,

Greetings to you!

Camel version: 3.20.4
Spring Boot version: 2.7.11
JDK: Amazon Corretto 17
Platform: Windows server 2019
IDE: IntelliJ IDEA 2021.3.2 (Community Edition)
Stack Traces & logging output: attached at the end

I have a case that two routes use the same HTTP listening URL but different 
backend, one is mater and another is backup. Normally during the Camel start 
only master route should be started, the backup route should be in stop status. 
When the master route corresponding backend got issue we can manually start the 
backup route and stop the master route.

The problem is that during Camel startup it will try to start all routes and 
failed due to below error:

---
 Application run 
failed","logger_name":"org.springframework.boot.SpringApplication","thread_name":"main","level":"ERROR","level_value":4,"stack_trace":"org.apache.camel.FailedToStartRouteException:
 Failed to start route SMS_JSON_MsgFlow because of Multiple consumers for the 
same endpoint is not allowed: 
jetty:http://0.0.0.0:7806/esb00/helmjson?httpMethodRestrict=POST&matchOnUriPrefix=true
---

I read the Camel document and seems RoutePolicy[1] could be the solution, so I 
take class ThrottlingInflightRoutePolicy as reference and extend class 
RoutePolicySupport and override method onStart as below, however seems it not 
works. I can see it print the log "stop omni channel interface: " on console 
but the CamelContext still try to start the route and got issue.

Could you kindly advise on this? Thanks in advance!

---
@Override
public void onStart(Route route) {
System.out.println("starting route: " + route.getRouteId());
boolean startOmniChannel = 
Boolean.parseBoolean(String.valueOf(camelContext.getPropertiesComponent().resolveProperty("start_omni_channel")));
if (!startOmniChannel) {
try {
System.out.println("stop omni channel interface: " + 
route.getRouteId());
suspendOrStopConsumer(route.getConsumer());
} catch (Exception e) {
e.printStackTrace();
}
}
}
---

Stack Traces & logging output:
---
{"@timestamp":"2023-08-28T10:58:07.52+08:00","@version":"1","message":"Apache 
Camel 3.20.4 (mini-esb) is 
starting","logger_name":"org.apache.camel.impl.engine.AbstractCamelContext","thread_name":"main","level":"INFO","level_value":2}
{"@timestamp":"2023-08-28T10:58:07.62+08:00","@version":"1","message":"Starting 
CamelMainRunController to ensure the main thread keeps 
running","logger_name":"org.apache.camel.spring.boot.CamelSpringBootApplicationListener","thread_name":"main","level":"INFO","level_value":2}
{"@timestamp":"2023-08-28T10:58:07.622+08:00","@version":"1","message":"Apache 
Camel (Main) 3.20.4 is 
starting","logger_name":"org.apache.camel.main.MainSupport","thread_name":"CamelMainRunController","level":"INFO","level_value":2}
{"@timestamp":"2023-08-28T10:58:07.642+08:00","@version":"1","message":"Logging 
initialized @5011ms to 
org.eclipse.jetty.util.log.Slf4jLog","logger_name":"org.eclipse.jetty.util.log","thread_name":"main","level":"INFO","level_value":2}
{"@timestamp":"2023-08-28T10:58:08.1+08:00","@version":"1","message":"jetty-9.4.51.v20230217;
 built: 2023-02-17T08:19:37.309Z; git: 
b45c405e4544384de066f814ed42ae3dceacdd49; jvm 
17.0.7+7-LTS","logger_name":"org.eclipse.jetty.server.Server","thread_name":"main","level":"INFO","level_value":2}
{"@timestamp":"2023-08-28T10:58:08.53+08:00","@version":"1","message":"Started 
o.e.j.s.ServletContextHandler@4c635edc{/,null,AVAILABLE}","logger_name":"org.eclipse.jetty.server.handler.ContextHandler","thread_name":"main","level":"INFO","level_value":2}
{"@timestamp":"2023-08-28T10:58:08.994+08:00","@version":"1","message":"Started 
ServerConnector@3009eed7{HTTP/1.1, 
(http/1.1)}{0.0.0.0:7806}","logger_name":"org.eclipse.jetty.server.AbstractConnector","thread_name":"main","level":"INFO","level_value":2}
{"@timestamp":"2023-08-28T10:58:08.994+08:00","@version":"1","message":"Started 
@6363ms","logger_name":"org.eclipse.jetty.server.Server","thread_name":"main","level":"INFO","level_value":2}
{"@timestamp":"2023-08-28T10:58:09.011+08:00","@version":"1","message":"Error 
starting CamelContext (mini-esb) due to exception thrown: Failed to start route 
SMS_JSON_MsgFlow because of Multiple consumers for the same endpoint is not 
allowed: 
jetty:http://0.0.0.0:7806/esb00/helmjson?httpMethodRestrict=POST&matchOnUriPrefix=true","logger_name":"org.apache.camel.impl.engine.AbstractCamelContext","thread_name":"main","level":"ERROR","level_value":4,"stack_trace":"org.apache.camel.FailedToStartRouteException:
 Failed to start route SMS_JSON_MsgFlow because of Multiple consumers for the 
same endpoint is not allowed: 
jetty:http://0.0.0.0:7806/esb00/helmjson?httpMethodRestrict=POST&matchOnUriPrefix=true\r\n\tat
 
org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRouteConsumers(I

RE: How to use RoutePolicy to prevent a route from starting

2023-08-28 Thread Han Yainsun
Hi Jacek,

Thanks for the advice! Yes this feature meet my needs.

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

From: jacek szymanski<mailto:jacek.p.szyman...@gmail.com>
Sent: 2023年8月28日 20:29
To: users@camel.apache.org<mailto:users@camel.apache.org>
Subject: Re: How to use RoutePolicy to prevent a route from starting

Hi,

wouldn't it be enough to disable auto startup on the backup route?


https://camel.apache.org/manual/configuring-route-startup-ordering-and-autostartup.html


js.



On 28.08.2023 9:31, Han Yainsun wrote:
> Hi Camel Community,
>
> Greetings to you!
>
> Camel version: 3.20.4
> Spring Boot version: 2.7.11
> JDK: Amazon Corretto 17
> Platform: Windows server 2019
> IDE: IntelliJ IDEA 2021.3.2 (Community Edition)
> Stack Traces & logging output: attached at the end
>
> I have a case that two routes use the same HTTP listening URL but different 
> backend, one is mater and another is backup. Normally during the Camel start 
> only master route should be started, the backup route should be in stop 
> status. When the master route corresponding backend got issue we can manually 
> start the backup route and stop the master route.
>
> The problem is that during Camel startup it will try to start all routes and 
> failed due to below error:
>
> ---
>   Application run 
> failed","logger_name":"org.springframework.boot.SpringApplication","thread_name":"main","level":"ERROR","level_value":4,"stack_trace":"org.apache.camel.FailedToStartRouteException:
>  Failed to start route SMS_JSON_MsgFlow because of Multiple consumers for the 
> same endpoint is not allowed: 
> jetty:http://0.0.0.0:7806/esb00/helmjson?httpMethodRestrict=POST&matchOnUriPrefix=true
> ---
>
> I read the Camel document and seems RoutePolicy[1] could be the solution, so 
> I take class ThrottlingInflightRoutePolicy as reference and extend class 
> RoutePolicySupport and override method onStart as below, however seems it not 
> works. I can see it print the log "stop omni channel interface: " on console 
> but the CamelContext still try to start the route and got issue.
>
> Could you kindly advise on this? Thanks in advance!
>
> ---
>  @Override
>  public void onStart(Route route) {
>  System.out.println("starting route: " + route.getRouteId());
>  boolean startOmniChannel = 
> Boolean.parseBoolean(String.valueOf(camelContext.getPropertiesComponent().resolveProperty("start_omni_channel")));
>  if (!startOmniChannel) {
>  try {
>  System.out.println("stop omni channel interface: " + 
> route.getRouteId());
>  suspendOrStopConsumer(route.getConsumer());
>  } catch (Exception e) {
>  e.printStackTrace();
>  }
>  }
>  }
> ---
>
> Stack Traces & logging output:
> ---
> {"@timestamp":"2023-08-28T10:58:07.52+08:00","@version":"1","message":"Apache 
> Camel 3.20.4 (mini-esb) is 
> starting","logger_name":"org.apache.camel.impl.engine.AbstractCamelContext","thread_name":"main","level":"INFO","level_value":2}
> {"@timestamp":"2023-08-28T10:58:07.62+08:00","@version":"1","message":"Starting
>  CamelMainRunController to ensure the main thread keeps 
> running","logger_name":"org.apache.camel.spring.boot.CamelSpringBootApplicationListener","thread_name":"main","level":"INFO","level_value":2}
> {"@timestamp":"2023-08-28T10:58:07.622+08:00","@version":"1","message":"Apache
>  Camel (Main) 3.20.4 is 
> starting","logger_name":"org.apache.camel.main.MainSupport","thread_name":"CamelMainRunController","level":"INFO","level_value":2}
> {"@timestamp":"2023-08-28T10:58:07.642+08:00","@version":"1","message":"Logging
>  initialized @5011ms to 
> org.eclipse.jetty.util.log.Slf4jLog","logger_name":"org.eclipse.jetty.util.log","thread_name":"main","level":"INFO","level_value":2}
> {"@timestamp":"2023-08-28T10:58:08.1+08:00","@version":"1","message":"jetty-9.4.51.v20230217;
>  built: 2023-02-17T08:19:37.309Z; git: 
> b45c405e4544384de066f814ed42

Jetty Component how to add additional steps after send http response back to the client

2023-11-13 Thread Han Yainsun
Dear Camel Community and Camel users,

Greetings to you!

Camel version: 3.20.4
Spring Boot version: 2.7.11
JDK: Amazon Corretto 17
Platform: Windows server 2019
IDE: IntelliJ IDEA 2021.3.2 (Community Edition)

I have an requirement that need calculate each message process time, incould 
total process time and backend process time. the route likes below, it seems 
that the jetty managed the http session and send the response  back to client 
automatically at the end of route.

Is it possible to explicitly inform jetty send the resonse at specific point?

Thansk in advance.

  from("jetty:http://0.0.0.0:8080/test";)
  .process(exchange -> exchange.setProperty("inbound timestamp", 
System.currentTimeMillis()))
  .to("http://localhost/mockbackend";)  
  .process(exchange -> exchange.setProperty("backend respond timestamp", 
System.currentTimeMillis()))
  .setBody(constant("hello"))
  // I expect jetty send response back to client here.
  .process(exchange -> exchange.setProperty("backend respond timestamp", 
System.currentTimeMillis()));



回复: Jetty Component how to add additional steps after send http response back to the client

2023-11-17 Thread Han Yainsun
Dear all,

Does anyone have idea regarding this question? Or any workaroud?

I appreciate all the inputs.

Thanks in advance~

发件人: Han Yainsun 
发送时间: 2023年11月14日 4:09
收件人: users@camel.apache.org 
主题: Jetty Component how to add additional steps after send http response back 
to the client

Dear Camel Community and Camel users,

Greetings to you!

Camel version: 3.20.4
Spring Boot version: 2.7.11
JDK: Amazon Corretto 17
Platform: Windows server 2019
IDE: IntelliJ IDEA 2021.3.2 (Community Edition)

I have an requirement that need calculate each message process time, incould 
total process time and backend process time. the route likes below, it seems 
that the jetty managed the http session and send the response  back to client 
automatically at the end of route.

Is it possible to explicitly inform jetty send the resonse at specific point?

Thansk in advance.

  from("jetty:http://0.0.0.0:8080/test";)
  .process(exchange -> exchange.setProperty("inbound timestamp", 
System.currentTimeMillis()))
  .to("http://localhost/mockbackend";)  
  .process(exchange -> exchange.setProperty("backend respond timestamp", 
System.currentTimeMillis()))
  .setBody(constant("hello"))
  // I expect jetty send response back to client here.
  .process(exchange -> exchange.setProperty("backend respond timestamp", 
System.currentTimeMillis()));



Re: Jetty Component how to add additional steps after send http response back to the client

2023-11-20 Thread Han Yainsun
Dear Claus lbsen,

Thanks so much for your suggestions, I will try both.

Thanks again for your kind help. Have a nice day. :)


From: Claus Ibsen 
Sent: Sunday, November 19, 2023 3:36:23 AM
To: users@camel.apache.org 
Subject: Re: Jetty Component how to add additional steps after send http 
response back to the client

Hi

I would also add that HTTP servers like Tomcat, Jetty, JBoss etc have an
access log that logs how long time each request takes. And they often have
a API / plugin you can use to have your custom code triggered by the HTTP
server
so you can do any kind of "how long time it takes" you need.


On Sat, Nov 18, 2023 at 8:34 PM Claus Ibsen  wrote:

> Hi
>
> Camel will send back the response at the end of the route in the consumer,
> so what you do in that route example will not work.
> However if you want to do some kind of custom logging of how long it
> takes, then Camel Jetty has send back the response to the client, when the
> UnitOfWork is done.
> So you can use Camel's UoW done to do any custom code for "backend
> response timestamp ...".
>
> See the docs for UnitOfWork or its also covered in the CiA2 book.
>
>
>
> On Tue, Nov 14, 2023 at 5:11 AM Han Yainsun  wrote:
>
>> Dear Camel Community and Camel users,
>>
>> Greetings to you!
>>
>> Camel version: 3.20.4
>> Spring Boot version: 2.7.11
>> JDK: Amazon Corretto 17
>> Platform: Windows server 2019
>> IDE: IntelliJ IDEA 2021.3.2 (Community Edition)
>>
>> I have an requirement that need calculate each message process time,
>> incould total process time and backend process time. the route likes below,
>> it seems that the jetty managed the http session and send the response
>> back to client automatically at the end of route.
>>
>> Is it possible to explicitly inform jetty send the resonse at specific
>> point?
>>
>> Thansk in advance.
>>
>> from("jetty:http://0.0.0.0:8080/test";)
>> .process(exchange -> exchange.setProperty("inbound timestamp",
>> System.currentTimeMillis()))
>> .to("http://localhost/mockbackend";)
>> .process(exchange -> exchange.setProperty("backend respond timestamp",
>> System.currentTimeMillis()))
>> .setBody(constant("hello"))
>> // I expect jetty send response back to client here.
>> .process(exchange -> exchange.setProperty("backend respond timestamp",
>> System.currentTimeMillis()));
>>
>>
>
> --
> Claus Ibsen
> -
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


--
Claus Ibsen
-
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2