Apache骆驼错误:由于以下原因未能提取身体:

发布于 2025-01-27 21:54:01 字数 4621 浏览 2 评论 0原文

我尝试使用Apache Camel框架的下一个情况:

  1. 获取CSV文件
  2. 拆分数据,然后将其发送到队列中的排列
  3. 数据中,从队列

CSV文件中接收到数据:

"id","from","to","conversionMultiple"
"1001","USD","INR","70"
"1002","EUR","INR","80"
"1003","AUD","INR","10"

队列创建:

        from(csvFolder)
                .unmarshal().csv()
                .split(body())
                .log("${body}") // <---- (1)
                .to(QUEUE_NAME);

队列接收:

        from(QUEUE_NAME) // <----------- (2)
                .log("${body}");

因此,拆分后的身体(1)看起来像这样。 (四个不同的消息):

2022-05-09 21:32:58.499  INFO 16999 --- [ile://files/csv] route1                                   : id,from,to,conversionMultiple
2022-05-09 21:32:58.631  INFO 16999 --- [ile://files/csv] route1                                   : 1001,USD,INR,70
2022-05-09 21:32:58.677  INFO 16999 --- [ile://files/csv] route1                                   : 1002,EUR,INR,80
2022-05-09 21:32:58.694  INFO 16999 --- [ile://files/csv] route1                                   : 1003,AUD,INR,10

消息成功传递给队列,但是,当我尝试从队列(2)接收数据时,我收到了错误:


> 2022-05-09 21:32:58.727  WARN 71292 --- [emq-json-queue]]
> o.a.c.c.jms.EndpointMessageListener      : Execution of JMS message
> listener failed. Caused by: [org.apache.camel.RuntimeCamelException -
> Failed to extract body due to: javax.jms.JMSException: Failed to build
> body from content. Serializable class not available to broker. Reason:
> java.lang.ClassNotFoundException: Forbidden class java.util.ArrayList!
> This class is not trusted to be serialized as ObjectMessage payload.
> Please take a look at http://activemq.apache.org/objectmessage.html
> for more information on how to configure trusted classes.. Message:
> ActiveMQObjectMessage {commandId = 12, responseRequired = true,
> messageId = ID:C11852-54716-1652027839908-1:1:1:1:8,
> originalDestination = null, originalTransactionId = null, producerId =
> ID:C11852-54716-1652027839908-1:1:1:1, destination =
> queue://my-activemq-json-queue, transactionId = null, expiration = 0,
> timestamp = 1652121178695, arrival = 0, brokerInTime = 1652121178697,
> brokerOutTime = 1652121178721, correlationId = null, replyTo = null,
> persistent = true, type = null, priority = 4, groupID = null,
> groupSequence = 0, targetConsumerId = null, compressed = false, userID
> = null, content = org.apache.activemq.util.ByteSequence@10f189a5, marshalledProperties = org.apache.activemq.util.ByteSequence@3f4a693f,
> dataStructure = null, redeliveryCounter = 0, size = 0, properties =
> {CamelFileLastModified=1611144622000, CamelFileParent=files/csv,
> CamelMessageTimestamp=1611144622000, CamelFilePath=files/csv/data.csv,
> CamelFileNameConsumed=data.csv, CamelFileLength=109,
> CamelFileRelativePath=data.csv, CamelFileAbsolute=false,
> CamelFileAbsolutePath=/Users/vhruzytskyi/IdeaProjects/camel-microservice-a/files/csv/data.csv,
> CamelFileName=data.csv, CamelFileNameOnly=data.csv},
> readOnlyProperties = true, readOnlyBody = true, droppable = false,
> jmsXGroupFirstForConsumer = false}]

build.gradle:

plugins {
    id 'org.springframework.boot' version '2.6.7'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.education'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

ext{
    camelVersion='3.16.0'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation "org.apache.camel.springboot:camel-spring-boot-starter:$camelVersion"
    implementation group: 'org.apache.camel.springboot', name: 'camel-activemq-starter', version: camelVersion
    implementation group: 'org.apache.camel.springboot', name: 'camel-kafka-starter', version: camelVersion
    implementation group: 'org.apache.camel.springboot', name: 'camel-http-starter', version: camelVersion
    implementation group: 'org.apache.camel.springboot', name: 'camel-csv-starter', version: camelVersion
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}


,为什么我在拆分后无法接收消息?

ps 我成功地收到数据而无需分裂,因此所有设置都是正确的

I try to use the next case with Apache Camel framework:

  1. Get the CSV file
  2. Split data and send it to the queue
  3. Recieve data from the queue

Csv file:

"id","from","to","conversionMultiple"
"1001","USD","INR","70"
"1002","EUR","INR","80"
"1003","AUD","INR","10"

Queue creation:

        from(csvFolder)
                .unmarshal().csv()
                .split(body())
                .log("${body}") // <---- (1)
                .to(QUEUE_NAME);

Queue receiving:

        from(QUEUE_NAME) // <----------- (2)
                .log("${body}");

So, the body after splitting (1) looks like this (four different messages):

2022-05-09 21:32:58.499  INFO 16999 --- [ile://files/csv] route1                                   : id,from,to,conversionMultiple
2022-05-09 21:32:58.631  INFO 16999 --- [ile://files/csv] route1                                   : 1001,USD,INR,70
2022-05-09 21:32:58.677  INFO 16999 --- [ile://files/csv] route1                                   : 1002,EUR,INR,80
2022-05-09 21:32:58.694  INFO 16999 --- [ile://files/csv] route1                                   : 1003,AUD,INR,10

Messages passed to the queue successfully, but, when I try to receive data from the queue (2) I got the error:


> 2022-05-09 21:32:58.727  WARN 71292 --- [emq-json-queue]]
> o.a.c.c.jms.EndpointMessageListener      : Execution of JMS message
> listener failed. Caused by: [org.apache.camel.RuntimeCamelException -
> Failed to extract body due to: javax.jms.JMSException: Failed to build
> body from content. Serializable class not available to broker. Reason:
> java.lang.ClassNotFoundException: Forbidden class java.util.ArrayList!
> This class is not trusted to be serialized as ObjectMessage payload.
> Please take a look at http://activemq.apache.org/objectmessage.html
> for more information on how to configure trusted classes.. Message:
> ActiveMQObjectMessage {commandId = 12, responseRequired = true,
> messageId = ID:C11852-54716-1652027839908-1:1:1:1:8,
> originalDestination = null, originalTransactionId = null, producerId =
> ID:C11852-54716-1652027839908-1:1:1:1, destination =
> queue://my-activemq-json-queue, transactionId = null, expiration = 0,
> timestamp = 1652121178695, arrival = 0, brokerInTime = 1652121178697,
> brokerOutTime = 1652121178721, correlationId = null, replyTo = null,
> persistent = true, type = null, priority = 4, groupID = null,
> groupSequence = 0, targetConsumerId = null, compressed = false, userID
> = null, content = org.apache.activemq.util.ByteSequence@10f189a5, marshalledProperties = org.apache.activemq.util.ByteSequence@3f4a693f,
> dataStructure = null, redeliveryCounter = 0, size = 0, properties =
> {CamelFileLastModified=1611144622000, CamelFileParent=files/csv,
> CamelMessageTimestamp=1611144622000, CamelFilePath=files/csv/data.csv,
> CamelFileNameConsumed=data.csv, CamelFileLength=109,
> CamelFileRelativePath=data.csv, CamelFileAbsolute=false,
> CamelFileAbsolutePath=/Users/vhruzytskyi/IdeaProjects/camel-microservice-a/files/csv/data.csv,
> CamelFileName=data.csv, CamelFileNameOnly=data.csv},
> readOnlyProperties = true, readOnlyBody = true, droppable = false,
> jmsXGroupFirstForConsumer = false}]

build.gradle:

plugins {
    id 'org.springframework.boot' version '2.6.7'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.education'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

ext{
    camelVersion='3.16.0'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation "org.apache.camel.springboot:camel-spring-boot-starter:$camelVersion"
    implementation group: 'org.apache.camel.springboot', name: 'camel-activemq-starter', version: camelVersion
    implementation group: 'org.apache.camel.springboot', name: 'camel-kafka-starter', version: camelVersion
    implementation group: 'org.apache.camel.springboot', name: 'camel-http-starter', version: camelVersion
    implementation group: 'org.apache.camel.springboot', name: 'camel-csv-starter', version: camelVersion
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}


So, why I can't receive messages after splitting?

PS
I successfully receive data without splitting, so all settings are correct

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文