【问题标题】:File not Found exception while trying to read file by using Apache-Camel尝试使用 Apache-Camel 读取文件时未找到文件异常
【发布时间】:2019-11-01 10:11:42
【问题描述】:

我有以下代码,它从 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 代码,并且代码能够成功读取文件。确切地说,我不知道问题出在哪里。是否遗漏了将文件放入 mq 的代码中的任何内容??

【问题讨论】:

    标签: java apache-camel ibm-mq


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多