为什么我的RabbitMQ消息无法使用Apache Beam进行序列化?

时间:2019-05-07 15:32:27

标签: rabbitmq apache-beam

我正在尝试使用Apache Beam读取RabbitMQ队列。 我已经编写了一些转换代码,以便将消息写入Kafka。 我什至使用简单的短信测试了自己的情况。

现在,我尝试使用使该变压器运行的有效消息来部署它。这些是大小适中的JSON消息。

奇怪的是,当我尝试读取“生产”消息时,我得到了此异常堆栈跟踪。

java.lang.IllegalArgumentException: Unable to encode element 'ValueWithRecordId{id=[], value=org.apache.beam.sdk.io.rabbitmq.RabbitMqMessage@f179a7f}' with coder 'ValueWithRecordId$ValueWithRecordIdCoder(org.apache.beam.sdk.coders.SerializableCoder@76190fb2)'.
        org.apache.beam.sdk.coders.Coder.getEncodedElementByteSize(Coder.java:300)
        org.apache.beam.sdk.coders.Coder.registerByteSizeObserver(Coder.java:291)
        org.apache.beam.sdk.util.WindowedValue$FullWindowedValueCoder.registerByteSizeObserver(WindowedValue.java:564)
        org.apache.beam.sdk.util.WindowedValue$FullWindowedValueCoder.registerByteSizeObserver(WindowedValue.java:480)
        org.apache.beam.runners.dataflow.worker.IntrinsicMapTaskExecutorFactory$ElementByteSizeObservableCoder.registerByteSizeObserver(IntrinsicMapTaskExecutorFactory.java:400)
        org.apache.beam.runners.dataflow.worker.util.common.worker.OutputObjectAndByteCounter.update(OutputObjectAndByteCounter.java:125)
        org.apache.beam.runners.dataflow.worker.DataflowOutputCounter.update(DataflowOutputCounter.java:64)
        org.apache.beam.runners.dataflow.worker.util.common.worker.OutputReceiver.process(OutputReceiver.java:43)
        org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation.runReadLoop(ReadOperation.java:201)
        org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation.start(ReadOperation.java:159)
        org.apache.beam.runners.dataflow.worker.util.common.worker.MapTaskExecutor.execute(MapTaskExecutor.java:77)
        org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker.process(StreamingDataflowWorker.java:1283)
        org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker.access$1000(StreamingDataflowWorker.java:147)
        org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker$6.run(StreamingDataflowWorker.java:1020)
        java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        java.lang.Thread.run(Thread.java:745)
Caused by: java.io.NotSerializableException: com.rabbitmq.client.impl.LongStringHelper$ByteArrayLongString
        java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
        java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        java.util.HashMap.internalWriteEntries(HashMap.java:1785)
        java.util.HashMap.writeObject(HashMap.java:1362)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        java.lang.reflect.Method.invoke(Method.java:498)
        java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
        java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
        java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
        java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        org.apache.beam.sdk.coders.SerializableCoder.encode(SerializableCoder.java:183)
        org.apache.beam.sdk.coders.SerializableCoder.encode(SerializableCoder.java:53)
        org.apache.beam.sdk.values.ValueWithRecordId$ValueWithRecordIdCoder.encode(ValueWithRecordId.java:105)
        org.apache.beam.sdk.values.ValueWithRecordId$ValueWithRecordIdCoder.encode(ValueWithRecordId.java:99)
        org.apache.beam.sdk.values.ValueWithRecordId$ValueWithRecordIdCoder.encode(ValueWithRecordId.java:81)
        org.apache.beam.sdk.coders.Coder.getEncodedElementByteSize(Coder.java:297)
        org.apache.beam.sdk.coders.Coder.registerByteSizeObserver(Coder.java:291)
        org.apache.beam.sdk.util.WindowedValue$FullWindowedValueCoder.registerByteSizeObserver(WindowedValue.java:564)
        org.apache.beam.sdk.util.WindowedValue$FullWindowedValueCoder.registerByteSizeObserver(WindowedValue.java:480)
        org.apache.beam.runners.dataflow.worker.IntrinsicMapTaskExecutorFactory$ElementByteSizeObservableCoder.registerByteSizeObserver(IntrinsicMapTaskExecutorFactory.java:400)
        org.apache.beam.runners.dataflow.worker.util.common.worker.OutputObjectAndByteCounter.update(OutputObjectAndByteCounter.java:125)
        org.apache.beam.runners.dataflow.worker.DataflowOutputCounter.update(DataflowOutputCounter.java:64)
        org.apache.beam.runners.dataflow.worker.util.common.worker.OutputReceiver.process(OutputReceiver.java:43)
        org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation.runReadLoop(ReadOperation.java:201)
        org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation.start(ReadOperation.java:159)
        org.apache.beam.runners.dataflow.worker.util.common.worker.MapTaskExecutor.execute(MapTaskExecutor.java:77)
        org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker.process(StreamingDataflowWorker.java:1283)
        org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker.access$1000(StreamingDataflowWorker.java:147)
        org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker$6.run(StreamingDataflowWorker.java:1020)
        java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        java.lang.Thread.run(Thread.java:745)

我的理解是RabbitMQ阅读器认为消息足够大,需要使用LongString,该消息无法序列化。

我对吗?如果是这样,我如何建议RabbitMQ使用简单的String(对于这些消息而言就足够了)?

1 个答案:

答案 0 :(得分:1)

这是一个Apache Beam(https://issues.apache.org/jira/browse/BEAM-7414),其解决方案...尚未由于纯粹的惰性而合并到Apache Beam回购中(这很糟糕)。如果有人想立即获得修复,则可以建立我的分支https://github.com/Riduidel/beam/tree/fix/rabbitmq-message-not-serializable