Camel Context failed to start due to connection (RPC connection) error with Corda node - apache-camel

My Spring boot camel application uses camel-corda component and failing to start when corda node (RPC connection) is not up and running
My current camel route is
#Component
class CordaOpsRouteBuilder() : RouteBuilder() {
override fun configure() {
from("timer://terminate?repeatCount=1&delay=20").autoStartup("{{corda.terminate.node}}")
.to("direct:terminate-node")
from("direct:terminate-node")
.log("Draining and shutting down node")
.to("corda://{{corda.rpc.username}}:{{corda.rpc.password}}#{{corda.rpc.host}}:{{corda.rpc.port}}?operation=TERMINATE")
.delay(10000).asyncDelayed()
.to("direct:shutdown")
from ("direct:shutdown")
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.to("http://localhost:{{server.port}}/actuator/shutdown")
}
}
Stack trace :
Caused by: org.apache.camel.RuntimeCamelException: net.corda.client.rpc.RPCException: Cannot connect to server(s). Tried with all available servers.
at org.apache.camel.RuntimeCamelException.wrapRuntimeCamelException(RuntimeCamelException.java:52) ~[camel-api-3.0.0-RC3.jar:3.0.0-RC3]
at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:63) ~[camel-support-3.0.0-RC3.jar:3.0.0-RC3]
How can handle above RuntimeCamelException during the startup?

Please use lazyStartProducer=true parameter on the corda endpoint to make sure the route starts even if corda is not available (a lazy start).
https://camel.apache.org/components/latest/corda-component.html

Related

CXF 3.5.5 Client API - causes java.lang.IncompatibleClassChangeError: org.apache.cxf.common.util.ASMHelper

I'm trying to use CXF 3.5.5 API for creating a WebClient to be able to invoke the CXF REST API.
When I create a WebClient, in CXF 3.5.5 , it gives the following exception.
While WebClient.create method is invoked in cxf 3.5.5, the ClassLoader throws Exception:
Caused by: java.lang.IncompatibleClassChangeError: org.apache.cxf.common.util.ASMHelper
This was working with CXF 3.3.7 version.
Any help is highly appreciated.
I'm trying to invoke the CXF REST API using CXF Client API WebClient.
List<Object> providers = new ArrayList<Object>();
providers.add(new com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider());
WebClient client = WebClient.create(serviceURL, providers);
client.encoding("UTF-8");
client.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON);
While WebClient.create method is invoked in cxf 3.5.5, the ClassLoader throws Exception:
Caused by: java.lang.IncompatibleClassChangeError: org.apache.cxf.common.util.ASMHelper

How do I shutdown and throw an exception when an Apache Camel FTP Route has a connection error?

I have the following Apache Camel FTP file download Route:
from(downloadUri)
.routeId(routeId)
.aggregate(new CustomListAggregationStrategy())
.constant(true)
.completionFromBatchConsumer()
.to("direct:" + routeDestinationId);
I add this Route to a context and then request data with a ConsumerTemplate:
List<ResultType> result = consumerTemplate.receiveBody(CAMEL_DIRECT_OBJECT_PREFIX
+ routeId, List.class);
When a connection error occurs (e.g. unknown host, host not reachable), I want to shutdown the Route and throw an exception after the "receiveBody" line where I try to read the downloaded files.
How can I do this?
I tried an onException-handler for the Route where I added a process block to it and called exchange.getContext().stop(); in that processing block. But the application just keeps running.
Stopping a route during routing an existing message is a bit tricky. The reason for that is Camel will Graceful Shutdown the route you are stopping. And if you do that while a message is being routed the Graceful Shutdown will try to wait until that message has been processed.
You can find more info here : https://camel.apache.org/manual/faq/how-can-i-stop-a-route-from-a-route.html

Apache Camel shuts down right after start, no reason logged, no exception thrown

I observe, that errors in the route definition lead to a silent shutdown of the application, caused by Camel. How can I configure Camel to telling me what exactly it dislikes.
Simple example: Assigning duplicate route names
If I define two routes with different names [by using: .id ("route name")], then the application starts and reports readiness.
If I mistakenly use a name twice, the application fails to start completely and Camel announces:
Apache Camel 2.22.0 (CamelContext: camel-1) is shutting down
Apache Camel 2.22.0 (CamelContext: camel-1) uptime 0.332 seconds
Apache Camel 2.22.0 (CamelContext: camel-1) is shutdown in 0.017 seconds
Stopping service [Tomcat]
HikariPool-1 - Shutdown initiated ...
HikariPool-1 - Shutdown completed.
Process finished with exit code 0
The exit code 0 seems to suggest a non-exceptional shutdown.
The same early shutdown happened, when I added a CronScheduledRoutePolicy to a route. [e.g. with .routePolicy (policy)]
It shuts down if I add a default instance or if I make any settings to the policy.
I increased the log level and got significantly more background noise, but no new findings. [using application.yml: logging: level: ROOT: DEBUG]
A try catch around the route definition didn't help. No exception was caught at the time of the route definition.
I tried to set the CronScheduledRoutePolicy an exception handler. [E.g. with policy.setExceptionHandler (myCamelExceptionHandlerLoggingEverything)]
Nothing got logged. No breakpoint was hit.
I would be very grateful for your help or references to any solutions.
Ralf
There are multiple ways to print an exact error and it depends on how developer design app/class with the camel route. I have mentioned below example which will give exact error you are looking for.
public class CamelPrintingExample {
public static void main(String[] args) throws Exception {
CamelContext camelContext = new DefaultCamelContext();
try {
camelContext.addRoutes(new RouteBuilder() {
public void configure() {
from("file:C:\\input\\").routeId("demo")
.to("file:C:\\output\\").end();
from("file:C:\\input\\").routeId("demo")
.to("file:C:\\output\\").end();
}
});
camelContext.start();
Thread.sleep(300000);
camelContext.stop();
} catch (Exception camelException) {
camelException.printStackTrace();
}
}
}
By running this I got below error.
org.apache.camel.FailedToStartRouteException: Failed to start route demo because of duplicate id detected: demo. Please correct ids to be unique among all your routes.
You can try defining a custom shutdown strategy. Read here
Try to add this in your route and then start it:
getContext().setTracing(true);
P.S. a problem could also be in your error handler

ERROR Closing socket for /127.0.0.1 because of error (kafka.network.Processor)

I'm new to apache camel and apache kafka and doing a small POC for my project. I am getting following issue error log when trying to read from kafka using Camel-kafka component.
[2016-01-20 08:47:10,979] INFO Closing socket connection to /127.0.0.1. (kafka.network.Processor)
[2016-01-20 08:47:44,643] INFO Closing socket connection to /127.0.0.1. (kafka.network.Processor)
[2016-01-20 08:47:54,545] ERROR Closing socket for /127.0.0.1 because of error (kafka.network.Processor)
java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
at sun.nio.ch.IOUtil.write(IOUtil.java:65)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:470)
at kafka.api.TopicDataSend.writeTo(FetchResponse.scala:123)
at kafka.network.MultiSend.writeTo(Transmission.scala:101)
at kafka.api.FetchResponseSend.writeTo(FetchResponse.scala:231)
at kafka.network.Processor.write(SocketServer.scala:472)
at kafka.network.Processor.run(SocketServer.scala:342)
at java.lang.Thread.run(Thread.java:745)
My java code is as follows:
public class Main {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("kafka:127.0.0.1:9092?topic=TEST&zookeeperHost=localhost&zookeeperPort=2181&groupId=group1")
/*.marshal(xmlJsonFormat)*/
.process(new XmlToJson())
/*.to("kafka:localhost:9092?topic=TestJson&zookeeperHost=localhost&zookeeperPort=2181&groupId=group1");*/
.to("file:/Users/himanshu/Desktop/TransCamelFuse/test.txt");
}
});
context.start();
Thread.sleep(10000);
context.stop();
}
}
I've put some txt from kafka producer console tool and trying to read using camel component of kafka.
It's not error.Giving this error because of your give data type. You are giving data to Kafka manually one by one.
You need to make sure the kafka server and kafka client versions are compatible to each i faced the same my kafka server was 0.8 and some spring beans uses kafka 2.4 libraries so whenever 2.4 client request for any kafka 0.8 operation server.log record this error
Solution
Be sure in code none of beans uses incompatible client for communication.

CXF Weblogic - Override CXF logger to Slf4j

We are using Apache CXF 2.5.2 for webservice client proxies. We use weblogic 10.3.4. To override the CXF logger we use the following option:
-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Slf4jLogger
For the org.apache.cxf.common.logging.Slf4jLogger, we've included the cxf-common-utilities-2.5.2 in our build.
When we try to deploy to weblogic we get the following exception:
[ERROR] Target state: deploy failed on Server AdminServer
[ERROR] java.lang.NoClassDefFoundError: weblogic/wsee/jaxws/spi/WLSProvider
According to documentation, your WebService client should have wseeclient.jar as it's runtime dependency. If the problems is still there, then include wlfullclient.jar (see Creating a wlfullclient.jar for JDK 1.6 client applications ).

Resources