- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试将 X?-GB 大文件作为流发送到 ActiveMQ 队列进行处理。
我知道 ActiveMQ supports streams ,camel-jms也是如此,但我尝试在队列中设置的任何内容似乎都没有任何区别。唯一改变的是关闭流缓存结果是一个“流关闭”异常。
我愿意使用处理器或自定义类(只要资源得到清理),但这在蓝图中应该是可能的。如何通过 camel-activemq 正确处理大文件而不会出现 OutOfMemoryError?
使用
这是我的 Camel 蓝图
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
<!-- just calls exchange.setBody(exchange.getBody(InputStream.class)) -->
<bean id="toStreamBody" class="my.test.toInputStream"/>
<!-- define a bean of type StreamCachingStrategy which CamelContext will automaticly use -->
<bean id="streamStrategy" class="org.apache.camel.impl.DefaultStreamCachingStrategy">
<property name="spoolDirectory" value="${java.io.tmpdir}TestTemp/#uuid#/"/>
<property name="spoolThreshold" value="131072"/>
<property name="spoolUsedHeapMemoryThreshold" value="70"/>
<property name="anySpoolRules" value="true"/>
</bean>
<!-- streamCaching="true" is "not a valid attribute" -->
<camelContext streamCache="true" xmlns="http://camel.apache.org/schema/blueprint">
<route id="file_route">
<from uri="file://FileUploadBin?delete=false&moveFailed=.error"/>
<!-- just calls exchange.setBody(exchange.getBody(InputStream.class)) -->
<bean ref="toStreamBody"/>
<to uri="activemq:queue:TestQ"/>
</route>
<route id="myTestQ">
<from uri="activemq:queue:TestQ?concurrentConsumers=1&maxConcurrentConsumers=64&maxMessagesPerTask=100&asyncConsumer=true&jmsMessageType=Stream&mapJmsMessage=false"/>
<bean ref="toStreamBody"/>
<log message="FINISHED" loggingLevel="WARN"/>
</route>
</camelContext>
</blueprint>
这是我不断收到的错误
2017-10-17 08:46:53,859 | ERROR | - RecipientList | DefaultErrorHandler | 43 - org.apache.camel.camel-core - 2.16.4 | Failed delivery for (MessageId: ID-DESKTOP-H2O66PO-62468-1508242908251-4-4 on ExchangeId: ID-DESKTOP-H2O66PO-62468-1508242908251-4-5). Exhausted after delivery attempt: 1 caught: org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: byte[] with value [Body is instance of org.apache.camel.StreamCache] due java.lang.OutOfMemoryError: Java heap space
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[file_route ] [file_route ] [file://FileUploadBin?delete=false&moveFailed=.error ] [ 3764]
Exchange
---------------------------------------------------------------------------------------------------------------------------------------
Exchange[
Id ID-DESKTOP-H2O66PO-62468-1508242908251-4-5
ExchangePattern InOnly
Headers {breadcrumbId=ID-DESKTOP-H2O66PO-62468-1508242908251-4-4, fileName=Die.txt}
BodyType org.apache.camel.converter.stream.FileInputStreamCache
Body [Body is instance of org.apache.camel.StreamCache]
]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: byte[] with value [Body is instance of org.apache.camel.StreamCache] due java.lang.OutOfMemoryError: Java heap space
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:610)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:137)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.core.osgi.OsgiTypeConverter.convertTo(OsgiTypeConverter.java:108)[40:org.apache.camel.camel-blueprint:2.16.4]
at org.apache.camel.component.jms.JmsBinding.createJmsMessageForType(JmsBinding.java:560)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsBinding.createJmsMessage(JmsBinding.java:490)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsBinding.makeJmsMessage(JmsBinding.java:303)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsProducer$2.createMessage(JmsProducer.java:300)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.doSendToDestination(JmsConfiguration.java:483)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.access$100(JmsConfiguration.java:426)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate$1.doInJms(JmsConfiguration.java:440)[46:org.apache.camel.camel-jms:2.16.4]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:466)[154:org.apache.servicemix.bundles.spring-jms:3.2.17.RELEASE_1]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:437)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:413)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:367)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:153)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.processor.MulticastProcessor.doProcessParallel(MulticastProcessor.java:823)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.processor.MulticastProcessor.access$200(MulticastProcessor.java:84)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:319)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:304)[43:org.apache.camel.camel-core:2.16.4]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_121]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
Caused by: org.apache.camel.RuntimeCamelException: java.lang.OutOfMemoryError: Java heap space
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1652)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:1247)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.impl.converter.StaticMethodTypeConverter.convertTo(StaticMethodTypeConverter.java:59)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.doConvertTo(BaseTypeConverterRegistry.java:293)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:120)[43:org.apache.camel.camel-core:2.16.4]
... 24 more
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3236)[:1.8.0_121]
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)[:1.8.0_121]
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)[:1.8.0_121]
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)[:1.8.0_121]
at java.nio.channels.Channels$WritableByteChannelImpl.write(Channels.java:458)[:1.8.0_121]
at sun.nio.ch.FileChannelImpl.transferToArbitraryChannel(FileChannelImpl.java:567)[:1.8.0_121]
at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:616)[:1.8.0_121]
at org.apache.camel.converter.stream.FileInputStreamCache.writeTo(FileInputStreamCache.java:108)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.converter.stream.StreamCacheConverter.convertToByteArray(StreamCacheConverter.java:102)[43:org.apache.camel.camel-core:2.16.4]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_121]
at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:1243)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.impl.converter.StaticMethodTypeConverter.convertTo(StaticMethodTypeConverter.java:59)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.doConvertTo(BaseTypeConverterRegistry.java:293)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:120)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.core.osgi.OsgiTypeConverter.convertTo(OsgiTypeConverter.java:108)
at org.apache.camel.component.jms.JmsBinding.createJmsMessageForType(JmsBinding.java:560)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsBinding.createJmsMessage(JmsBinding.java:490)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsBinding.makeJmsMessage(JmsBinding.java:303)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsProducer$2.createMessage(JmsProducer.java:300)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.doSendToDestination(JmsConfiguration.java:483)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.access$100(JmsConfiguration.java:426)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate$1.doInJms(JmsConfiguration.java:440)[46:org.apache.camel.camel-jms:2.16.4]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:466)[154:org.apache.servicemix.bundles.spring-jms:3.2.17.RELEASE_1]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:437)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:413)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:367)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:153)[46:org.apache.camel.camel-jms:2.16.4]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)[43:org.apache.camel.camel-core:2.16.4]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[43:org.apache.camel.camel-core:2.16.4]
2017-10-17 08:46:57,641 | WARN | ://FileUploadBin | GenericFileOnCompletion | 43 - org.apache.camel.camel-core - 2.16.4 | Rollback file strategy: org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy@294a3d48 for file: GenericFile[Die.txt]
最佳答案
这在经典的 ActiveMQ 代理上并不真正受支持。
然而,下一代 ActiveMQ Artemis 支持大消息,我们刚刚在 camel-jms 中也添加了对此的支持。我写了一篇关于这个的博客文章:http://www.davsclaus.com/2017/10/working-with-large-messages-using.html
我们还在 camel-jms 中添加了对 javax.jms.StreamMessage
类型的支持。但是,此 API 不适用于大消息,因此用途有限。但是你仍然可以打开它,在 Camel 2.21 中具有新选项 streamMessageTypeEnabled
的组件上,然后如果消息正文是流式类型那么 Camel 将作为 StreamMessage
发送而不是 BytesMessage
。
关于java - 如何使用 Camel 将大文件发送到ActiveMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46791397/
我创建了一个 spring-boot 应用程序,我在其中使用 camel-reSTLet 组件将我的 camel 路由公开为 rest 端点。 我的 camel 路由很简单:它们接受来自北向休息端点的
我有一条路由 (route1),它将数据发送到 HTTP 端点。为此,它必须设置授权 header 。 header 值每小时超时一次,必须更新。 为此,我创建了另一个路由 (route2),它使用提
我正在使用 camel-cdi,它正在注入(inject) CamelContext,检测项目中的所有路由。但是我想要一个带有注册表的 CamelContext,因为我有一些在 Camel route
我想使用来自网络服务的数据并将其放入 Camel eh-cache 中。后来我想通过 CacheManager 在 Camel 上下文之外使用这个缓存。我没有找到任何方法。 在下面的代码中,我跳过了
问题描述: 我无法从我的 Camel servlet 路由到 cxfbean。路由初始化失败并显示以下错误消息: "Failed to create route route1 at: >>> To[c
我想了解 Camel 中的工作单元概念。我有一个简单的问题,希望这里有人可以提供帮助。 例如,如果路由 Exchange 涉及多个路由 from("aws-sqs:Q1").to("direct:pr
首先是我正在尝试做的事情的基本轮廓 我有一个 MQ,我想从 读取消息 预处理 XML,并在 Exchange 上设置属性 发出 HTTP 请求 处理来自 http 请求和初始交换中的属性的数据 将其放
我有一个 SFTP 路由(在 Spring XML 中),它的 from 路径以每日更改的目录(即/yyyyMMdd)结尾,并且在 autoCreate=true 时一切正常或者路径开始时目录存在。但
如何用 Camel 实现这样的过程: 拆分 处理每个拆分的项目 聚合结果 如果发生异常: 停止 split 返回异常前所有item的聚合结果及异常信息 split时定义.stopOnException
我在 Camel 中有一条路线,我想在发生异常时重试,但我想设置一个属性,以便路线第二次可以做一些稍微不同的事情,以尝试阻止错误在重试时再次发生。这是说明我目前正在尝试的想法的路线。 from("di
这两个有何不同 from(endpoint).to(endpoint:a, endpoint:b) from(endpoint).multicast().to(endpoint:a, endpoint
我的 Camel 路线如下(示例) from (activemq:xyz) --- 从 QUEUE 接收消息 to(smpp:abc) --- 提交短信至短信中心 to(cxf:hij) --- 基于
我的 Camel 路线如下(示例) from (activemq:xyz) --- 从队列接收消息 to(smpp:abc) --- 将消息提交给 SMSC to(cxf:hij) --- 基于 SM
当捕获异常时,有什么方法可以停止路由执行(显示日志消息后)? java.lang.IllegalA
我正在使用 Camel 进行集成。我有一个用例,其中 Camel 应该将 1 条消息从一个队列传输到另一个队列,但它不断向队列发送相同的消息。请查看我的以下路线: ProducerTemplate正在
当异常在多播内部抛出时,Camel 不会传播异常。 考虑到以下设置,其中 direct:route 从其 beanRef 抛出异常: rest("/...") .pos
有没有办法使用生产者模板设置 Camel 交换属性? 想象一个接收客户订单的休息端点(尚未在 Camel route )。使用生产者模板,我想 在交易所上设置客户 ID 属性。 稍后在路由 需要时使用
再见,我的基本要求是有一个可以发送消息的路由,并将其放在 JMS 队列中。 camel 上下文在 JavaEE 6 容器中运行,即 JBoss AS 7.1.1,因此它是 HornetQ for JM
Camel 2.23.1 Karaf 4.2.4 白羊座蓝图(用于注册所有内容的外部容器) Camel 蓝图(用于 Camel 路线) Camel CXF(用于 rsServer) CXF 核心(用于
现在我在 Java EE 7 应用程序上使用 JMS 2.0 和 Artemis 1.2.0,我想用 Camel 做一些集成任务。 现在查看 camel-jms 文档,没有提及如何使用通用的 came
我是一名优秀的程序员,十分优秀!