admin管理员组

文章数量:1356333

I am trying to report latency metric for an Apache Camel Route by adding a bean at the end of the route and calculating the latency using the MESSAGE_TIMESTAMP field of the Exchange Message object.

The code is like this:

from("google-pubsub://...")
            .process()
            .bean("routeMetricsTimer","reportTimer");

In the RouteMetricsTimer bean, I tried to

        long messageTimeStamp = exchange.getMessage().getMessageTimestamp();
        long duration = System.currentTimeMillis() - messageTimeStamp;
        //report the time taken to process the message
        

However I see that the MESSAGE_TIMESTAMP value is always 0.

Is there a setting to enable this attribute in the message?

I see this related answer suggests adding a timestamp property at the beginning of the route, but this question is about the MESSAGE_TIMESTAMP field.

I am trying to report latency metric for an Apache Camel Route by adding a bean at the end of the route and calculating the latency using the MESSAGE_TIMESTAMP field of the Exchange Message object.

The code is like this:

from("google-pubsub://...")
            .process()
            .bean("routeMetricsTimer","reportTimer");

In the RouteMetricsTimer bean, I tried to

        long messageTimeStamp = exchange.getMessage().getMessageTimestamp();
        long duration = System.currentTimeMillis() - messageTimeStamp;
        //report the time taken to process the message
        

However I see that the MESSAGE_TIMESTAMP value is always 0.

Is there a setting to enable this attribute in the message?

I see this related answer suggests adding a timestamp property at the beginning of the route, but this question is about the MESSAGE_TIMESTAMP field.

https://stackoverflow/a/40522414/6352160

Share Improve this question asked Mar 28 at 1:07 ShankarShankar 2,8453 gold badges30 silver badges58 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

According to the doco: Message -Apache Camel

  • timestamp: the timestamp the message originates from. Some systems like JMS, Kafka, AWS have a timestamp on the event/message that Camel receives. This method returns the timestamp if a timestamp exists.

It comes down to google-pubsub protocol on whether it includes timestamp as part of its message. You might need to explicitly assign the timestamp prior to sending to the pubsub protocol.

本文标签: javaApache Camel ExchangeMessage timestamp field is emptyStack Overflow