Исключение файла не найдено при попытке прочитать файл с помощью Apache-Camel - PullRequest
1 голос
/ 18 июня 2019

У меня есть код ниже, который читает файл из системы 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 ??

1 Ответ

3 голосов
/ 18 июня 2019

URI, который у вас есть, должен быть путем к каталогу без имени файла.Вы можете указать имя файла с помощью опции fileName:

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

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

...