我正在尝试在spring引导应用程序(使用spring批处理)中使用camel运行cql查询。当我尝试在springbootweb应用程序中运行类似的代码时,它运行得很好,但是当我尝试使用commandlinerunner运行相同的代码时,它却没有。
我比较了两个应用程序的启动日志。问题似乎出在camel上下文的初始化中。它在web项目(使用@restcontroller)中得到了很好的初始化,但在commandlinerunner项目中似乎没有得到初始化。
web应用日志:
2020-01-22T10:48:25.214Z INFO SystemapiCassandraAccountByLpidhashApplication [{}]: Starting SystemapiCassandraAccountByLpidhashApplication on WV-MN14GLAE62KT with PID 15092 (C:\Repositories\Mule2SB\a0011-account-by-lpidhash\target\classes started by c052699 in C:\Repositories\Mule2SB\a0011-account-by-lpidhash)
2020-01-22T10:48:25.245Z INFO SystemapiCassandraAccountByLpidhashApplication [{}]: No active profile set, falling back to default profiles: default
2020-01-22T10:48:27.646Z INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker [{}]: Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$18670c03] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-22T10:48:28.137Z INFO TomcatWebServer [{}]: Tomcat initialized with port(s): 9084 (http)
2020-01-22T10:48:28.168Z INFO Http11NioProtocol [{}]: Initializing ProtocolHandler ["http-nio-9084"]
2020-01-22T10:48:28.187Z INFO StandardService [{}]: Starting service [Tomcat]
2020-01-22T10:48:28.188Z INFO StandardEngine [{}]: Starting Servlet engine: [Apache Tomcat/9.0.19]
2020-01-22T10:48:28.552Z INFO [/system-api/accountbylpidhash] [{}]: Initializing Spring embedded WebApplicationContext
2020-01-22T10:48:28.552Z INFO ContextLoader [{}]: Root WebApplicationContext: initialization completed in 3236 ms
2020-01-22T10:48:29.204Z INFO DefaultTypeConverter [{}]: Type converters loaded (core: 195, classpath: 11)
2020-01-22T10:48:29.622Z INFO GuavaCompatibility [{}]: Detected Guava >= 19 in the classpath, using modern compatibility layer
2020-01-22T10:48:29.650Z INFO core [{}]: DataStax Java driver 3.6.0 for Apache Cassandra
2020-01-22T10:48:29.922Z INFO Native [{}]: Could not load JNR C Library, native system calls through this library will not be available (set this logger level to DEBUG to see the full stack trace).
2020-01-22T10:48:29.922Z INFO ClockFactory [{}]: Using java.lang.System clock to generate timestamps.
2020-01-22T10:48:30.093Z INFO NettyUtil [{}]: Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
2020-01-22T10:48:32.048Z INFO DCAwareRoundRobinPolicy [{}]: Using data-center name 'Cassandra' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
2020-01-22T10:48:32.052Z INFO Cluster [{}]: New Cassandra host VMAKSA69901DV0/10.137.228.55:9042 added
2020-01-22T10:48:32.053Z INFO Cluster [{}]: New Cassandra host /10.126.240.191:9042 added
2020-01-22T10:48:32.927Z INFO ThreadPoolTaskExecutor [{}]: Initializing ExecutorService 'applicationTaskExecutor'
2020-01-22T10:48:33.575Z INFO EndpointLinksResolver [{}]: Exposing 2 endpoint(s) beneath base path ''
2020-01-22T10:48:33.780Z INFO RoutesCollector [{}]: Loading additional Camel XML routes from: classpath:camel/*.xml
2020-01-22T10:48:33.781Z INFO RoutesCollector [{}]: Loading additional Camel XML rests from: classpath:camel-rest/*.xml
2020-01-22T10:48:33.789Z INFO SpringCamelContext [{}]: Apache Camel 2.23.1 (CamelContext: camel-1) is starting
2020-01-22T10:48:33.794Z INFO ManagedManagementStrategy [{}]: JMX is enabled
2020-01-22T10:48:34.282Z INFO SpringCamelContext [{}]: StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2020-01-22T10:48:34.815Z INFO JacksonDataFormat [{}]: Found single ObjectMapper in Registry to use: com.fasterxml.jackson.databind.ObjectMapper@664db2ca
2020-01-22T10:48:34.925Z INFO JacksonDataFormat [{}]: Found single ObjectMapper in Registry to use: com.fasterxml.jackson.databind.ObjectMapper@664db2ca
2020-01-22T10:48:34.955Z INFO SpringCamelContext [{}]: Route: cli-lpidhash-accs started and consuming from: direct://cli-lpidhash-accs
2020-01-22T10:48:34.957Z INFO SpringCamelContext [{}]: Route: cli-total-lpidhash-accs started and consuming from: direct://cli-total-lpidhash-accs
2020-01-22T10:48:34.958Z INFO SpringCamelContext [{}]: Total 2 routes, of which 2 are started
2020-01-22T10:48:34.960Z INFO SpringCamelContext [{}]: Apache Camel 2.23.1 (CamelContext: camel-1) started in 1.175 seconds
2020-01-22T10:48:34.979Z INFO Http11NioProtocol [{}]: Starting ProtocolHandler ["http-nio-9084"]
2020-01-22T10:48:35.027Z INFO TomcatWebServer [{}]: Tomcat started on port(s): 9084 (http) with context path '/system-api/accountbylpidhash'
2020-01-22T10:48:35.036Z INFO SystemapiCassandraAccountByLpidhashApplication [{}]: Started SystemapiCassandraAccountByLpidhashApplication in 10.492 seconds (JVM running for 13.435)
commandlinerunner应用程序日志:
2020-01-22T10:49:40.378Z INFO RtPollMsdCreditCassandraAcctbyacctencodedApplication [{}]: Starting RtPollMsdCreditCassandraAcctbyacctencodedApplication on WV-MN14GLAE62KT with PID 23480 (started by c052699 in C:\Project Backups\InitialWorkspaces\rt-poll-msd-credit-cassandra-acctbyacctencoded)
2020-01-22T10:49:40.409Z INFO RtPollMsdCreditCassandraAcctbyacctencodedApplication [{}]: No active profile set, falling back to default profiles: default
2020-01-22T10:49:43.068Z INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker [{}]: Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$d8b1c963] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-22T10:49:43.089Z INFO PostProcessorRegistrationDelegate$BeanPostProcessorChecker [{}]: Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$b6880344] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-22T10:49:43.242Z WARN DefaultBatchConfigurer [{}]: No datasource was provided...using a Map based JobRepository
2020-01-22T10:49:43.242Z WARN DefaultBatchConfigurer [{}]: No transaction manager was provided, using a ResourcelessTransactionManager
2020-01-22T10:49:43.287Z INFO SimpleJobLauncher [{}]: No TaskExecutor has been set, defaulting to synchronous executor.
2020-01-22T10:49:43.700Z INFO GuavaCompatibility [{}]: Detected Guava >= 19 in the classpath, using modern compatibility layer
2020-01-22T10:49:43.721Z INFO core [{}]: DataStax Java driver 3.6.0 for Apache Cassandra
2020-01-22T10:49:44.010Z INFO Native [{}]: Could not load JNR C Library, native system calls through this library will not be available (set this logger level to DEBUG to see the full stack trace).
2020-01-22T10:49:44.011Z INFO ClockFactory [{}]: Using java.lang.System clock to generate timestamps.
2020-01-22T10:49:44.216Z INFO NettyUtil [{}]: Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
2020-01-22T10:49:46.239Z INFO DCAwareRoundRobinPolicy [{}]: Using data-center name 'Cassandra' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
2020-01-22T10:49:46.242Z INFO Cluster [{}]: New Cassandra host VMAKSA69901DV0/10.137.228.55:9042 added
2020-01-22T10:49:46.243Z INFO Cluster [{}]: New Cassandra host /10.126.240.191:9042 added
2020-01-22T10:49:47.088Z INFO DefaultTypeConverter [{}]: Type converters loaded (core: 195, classpath: 11)
2020-01-22T10:49:48.168Z INFO RoutesCollector [{}]: Loading additional Camel XML routes from: classpath:camel/*.xml
2020-01-22T10:49:48.170Z INFO RoutesCollector [{}]: Loading additional Camel XML rests from: classpath:camel-rest/*.xml
2020-01-22T10:49:48.191Z INFO RtPollMsdCreditCassandraAcctbyacctencodedApplication [{}]: Started RtPollMsdCreditCassandraAcctbyacctencodedApplication in 8.594 seconds (JVM running for 11.422)
2020-01-22T10:49:48.273Z INFO SimpleJobLauncher [{}]: Job: [SimpleJob: [name=rtPollMsdCreditJob]] launched with the following parameters: [{JobID=1579670388197}]
2020-01-22T10:49:48.299Z INFO SimpleStepHandler [{}]: Executing step: [rtPollNStoreStep]
我尝试在我使用它的地方初始化camelcontext和producertemplate(即在dao类中,也尝试在主springboot应用程序中初始化它,并尝试在dao类中自动连接它):
@Bean
public CamelContext camelContext() {
return new DefaultCamelContext();
}
@Bean
public ProducerTemplate producer() throws Exception {
return camelContext().createProducerTemplate();
}
(在网络应用程序中,我只是自动连线)
到目前为止运气不好。
[更新]
我将 Camel 上下文初始化为:
@Autowired
private ApplicationContext context;
@Bean
public CamelContext camelContext() {
return new SpringCamelContext(context);
}
路线也开始了:
2020-01-22T12:35:25.242Z INFO SpringCamelContext [{}]: Route: rt-poll-msd-credit started and consuming from: direct://rt-pollmsd-credit
2020-01-22T12:35:25.243Z INFO SpringCamelContext [{}]: Total 1 routes, of which 1 are started
现在,我得到的问题(警告)是:
2020-01-22T12:35:25.448Z INFO RtPollMsdCreditCassandraAcctbyacctencodedDao [{}]: query for insertAccountByLpidHash (insert in AccountByLpidhash): BEGIN BATCH insert into account_by_lpidhash(cust_lpid_hash,acct_nbr,prdt_cd,update_timestamp) values ('batchtestmklpo','123123','ccd','Wed Jan 22 12:35:25 IST 2020');insert into account_by_lpidhash(cust_lpid_hash,acct_nbr,prdt_cd,update_timestamp) values ('batchtestmklpo','31231','ccd','Wed Jan 22 12:35:25 IST 2020'); APPLY BATCH;
2020-01-22T12:35:25.449Z WARN SpringCamelContext [{}]: Cannot find the class loader from application context, using the thread context class loader instead
2020-01-22T12:35:25.458Z WARN SpringCamelContext [{}]: Cannot find the class loader from application context, using the thread context class loader instead
2020-01-22T12:35:25.460Z WARN SpringCamelContext [{}]: Cannot use SpringInjector as applicationContext is not a ConfigurableApplicationContext as its: null
2020-01-22T12:35:25.478Z INFO DefaultTypeConverter [{}]: Type converters loaded (core: 195, classpath: 11)
2020-01-22T12:36:00.058Z WARN SpringCamelContext [{}]: Cannot use SpringInjector as applicationContext is not a ConfigurableApplicationContext as its: null
我在responseexchange1对象中得到一个异常:
exceptiondetail:终结点上没有可用的使用者:direct://rt-pollmsd-credit. 交易所[id-wv-mn14glae62kt-1579679475416-2-1]
代码:
Exchange insertExchange1 = ExchangeBuilder.anExchange(camelContext()).withHeader(CassandraConstants.CQL_QUERY, cqlInsertQueryAccountByLpidhash.toString()).build();
Exchange responseExchange1 = producer().send(ApplicationConstants.URI_RT_POLL_MSD_CREDIT, insertExchange1);
String responseBody1 = responseExchange1.getIn().getBody(String.class);
暂无答案!
目前还没有任何答案,快来回答吧!