尝试使用 Apache-Camel 读取文件时未找到文件异常
File not Found exception while trying to read file by using Apache-Camel
我有以下代码,它从 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
调试信息显示 "no such file or directory"。我认为这是权限错误,我尝试使用正常的 java 代码,代码能够成功读取文件。确切地说,我不知道问题出在哪里。是否遗漏了将文件放入 mq 的代码中的任何内容??
你的uri应该是目录路径,没有文件名。您可以使用 fileName 选项指定文件名:
from("file:C:/apche_camel/wmq_inputs?fileName=file_Name.xml&noop=true")
我有以下代码,它从 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
调试信息显示 "no such file or directory"。我认为这是权限错误,我尝试使用正常的 java 代码,代码能够成功读取文件。确切地说,我不知道问题出在哪里。是否遗漏了将文件放入 mq 的代码中的任何内容??
你的uri应该是目录路径,没有文件名。您可以使用 fileName 选项指定文件名:
from("file:C:/apche_camel/wmq_inputs?fileName=file_Name.xml&noop=true")