尝试通过使用Apache-Camel读取文件时未找到文件异常

时间:2019-06-18 17:58:01

标签: java apache-camel ibm-mq

我有以下代码从Windows系统读取文件并将其放在ibm-mq中。我没有任何错误。但是,当我在IBM Queue中检查消息时,我没有任何消息。

   public class FileToJMS{ 

   public static void main(String args[]) throws Exception
   {
       final Map headers=new HashMap();
       headers.put("xxx","yy");
       headers.put("yyy","zzz");
       headers.put("xyz","1");
       CamelContext camelContext = new DefaultCamelContext();

        MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
        connectionFactory.setHostName("zrled201");
    try {
            connectionFactory.setPort(1234);
            connectionFactory.setQueueManager("xxxxx");
            connectionFactory.setChannel("channel");
            connectionFactory.setTransportType(1);
        } catch (JMSException e) {
            e.printStackTrace();
        }
        camelContext.addComponent("wmq", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

   try {
       camelContext.addRoutes(new RouteBuilder() {
           public void configure() throws Exception {
               from("file:C:/apche_camel/wmq_inputs/file_Name.xml?noop=true").process(new Processor() {
                   public void process(Exchange exchange) throws Exception {

                        exchange.getIn().setHeaders(headers);
                       }
                      })
                       .to("wmq:queue:ESB.ENTRY.SERVICE.IN");
               System.out.println("done");
           }
       });
   } catch (Exception e) {
       e.printStackTrace();
   }

   camelContext.start();
 Thread.sleep(10000);
   camelContext.stop();
   }

我在控制台上浏览了调试信息,发现了

之类的东西。
  [Camel (camel-1) thread #0 - 
  file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG 
 org.apache.camel.component.file.FileEndpoint  - Using Generic file 
 process strategy: 
 org.apache.camel.component.file.strategy.GenericFileRename
  ProcessStrategy@74b7bb95
 1691 [Camel (camel-1) thread #0 - 
 file://C:/apche_camel/wmq_inputs/JP_SH_TEST_04.xml] DEBUG 
 org.apache.camel.component.file.strategy.MarkerFileExclusive
ReadLockStrategy  - Prepare on startup by deleting orphaned lock 
 files from: C:\apche_camel\wmq_inputs\SH_TEST_04.xml
1691 [Camel (camel-1) thread #0 - 
file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG 
 org.apache.camel.component.file.FileConsumer  -
 Cannot poll as directory does not exists or its not a directory: 
 C:\apche_camel\wmq_inputs\SH_TEST_04.xml
 1691 [Camel (camel-1) thread #0 - 
  file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG 
 org.apache.camel.component.file.FileConsumer  - Took
 0.000 seconds to poll: C:\apche_camel\wmq_inputs\SH_TEST_04.xml
 2197 [Camel (camel-1) thread #0 - 
 file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG 
  org.apache.camel.component.file.FileConsumer  - 
 Cannot poll as directory does not exists or its not a directory: 
C:\apche_camel\wmq_inputs\SH_TEST_04.xml
2197 [Camel (camel-1) thread #0 - 
 file://C:/apche_camel/wmq_inputs/SH_TEST_04.xml] DEBUG 
org.apache.camel.component.file.FileConsumer  - Took 0.000 seconds to 
 poll: C:\apche_camel\wmq_inputs\_H_TEST_04.xml
  2696 [Camel (camel-1) thread #0 - 
 file://C:/apche_camel/wmq_inputs/_SH_TEST_04.xml] DEBUG 
  org.apache.camel.component.file.FileConsumer  - Cannot poll as directory 
  does not exists or its not a directory: 
  C:\apche_camel\wmq_inputs\SH_TEST_04.xml

可以看到调试信息显示“没有这样的文件或目录”。我以为是权限错误,因此尝试使用普通的Java代码,并且该代码能够读取文件sucessfull。完全我不知道问题出在哪里。是否错过了将文件放置到mq中的代码中的任何内容?

1 个答案:

答案 0 :(得分:3)

您拥有的uri应该是目录路径,没有文件名。您可以使用fileName选项指定文件名:

from("file:C:/apche_camel/wmq_inputs?fileName=file_Name.xml&noop=true")

https://camel.apache.org/file2.html