简体   繁体   English

Apache Storm中的自定义序列化

[英]Custom serialization in Apache Storm

I try to add custom serializer for my Objects which is used in Apache Storm Spouts/Bolts. 我尝试为Apache Storm Spouts / Bolts中使用的对象添加自定义序列化程序。 Right now my code looks like that: 现在,我的代码如下所示:

conf.registerSerialization(MyService.class, MyKryoSerializer.class);

public class MyKryoSerializer extends Serializer<MyService> {

    public MyKryoSerializer() {
        System.out.println("New MyKryoSerializaer!");
    }

    @Override
    public void write(Kryo kryo, Output output, MyService service) {
        System.out.println(72);
    }

    @Override
    public MyService read(Kryo kryo, Input input, Class<MyService> aClass) {
        System.out.println(73);
        return null;
    }

    public MyService copy(Kryo kryo, MyService myService) {
        System.out.println("MyService!");
        return myService;
    }
}

public class MyRandomSpout extends BaseRichSpout {

    private MyService service;

    private SpoutOutputCollector collector;

...

So, when I try to start Storm topology on my local cluster I will see "New MyKryoSerializaer!" 因此,当我尝试在本地群集上启动Storm拓扑时,我会看到"New MyKryoSerializaer!" in stdout , so constructor is called, but write/read methods are not called. stdout ,因此调用了构造函数,但未调用write / read方法。 Could anybody tell me, what do I wrong? 谁能告诉我,我怎么了? Does Storm support Skyo serializer for spots/bolts serialization? Storm是否支持Skyo序列化器进行斑点/螺栓序列化?

I had to add the following config to my topologies in order to get Storm to use my own serialization logic: 我必须将以下配置添加到拓扑中,以使Storm使用我自己的序列化逻辑:

config.put(Config.TOPOLOGY_FALL_BACK_ON_JAVA_SERIALIZATION, true);

where config is the configuration I eventually pass in to the submit method. 其中config是我最终传递给Submit方法的配置。

It doesn't look like Storm supports Kryo for serialization of bolts or spouts. Storm似乎不支持Kryo进行螺栓或喷口的序列化。 See this line where it explicitly tries to serialize with Java serialization. 请在此行中明确尝试使用Java序列化进行序列化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM