how to register kryo serializer instances in storm?

空扰寡人 提交于 2019-12-12 16:13:04

问题


I'm desparately trying to configure serializer instances to use in my storm topology.

The storm documentation states, there are 2 ways to register serializers :

1. The name of a class to register. In this case, Storm will use Kryo’s FieldsSerializer to serialize the class. This may or may not be optimal for the class – see the Kryo docs for more details.
2. A map from the name of a class to register to an implementation of com.esotericsoftware.kryo.Serializer.

I want to use 2. ->

Map<String, Object> serializerConfig = new HashMap<String, Object>();
serializerConfig.put(Record.class.getName(), new AvroSerializer(params));
conf.put(Config.TOPOLOGY_KRYO_REGISTER, serializerConfig);

Unfortunately, this results in

Exception in thread "main" java.lang.IllegalArgumentException: Storm conf is not valid. Must be json-serializable

on topology submission.

Does anyone know how to do this (register serializer instances) ?

Thank you very much


回答1:


There is a method in the backtype.storm.Config class to register your own class derived from Serializer.

For your example, put this in the main method that creates and submits the topology:

// Read in Storm Configuration
Config conf = new Config();
conf.registerSerialization(Record.class, AvroSerializer.class);



回答2:


As Steven Magana-Zook said above, you want to register the class in the config as he's done. This apparently doesn't let you pass in parameters, but if you look in SerializationFactory.java in storm's source, you can see that it resolves various possible constructors of your serializer class, including several that contain the storm Config. You can stash your parameters in there.

So not what you were hoping for exactly but you should be able to reach the same end.



来源:https://stackoverflow.com/questions/26470639/how-to-register-kryo-serializer-instances-in-storm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!