storm的序列化问题及与spring的结合方式
2015-01-20 11:44
232 查看
最近打算在项目中用storm从一个database生成多个搜索引擎的实时索引, 于是看了一些相关的资料就开始上手了. 按照以前熟悉的套路, 使用spring来管理对象之间的依赖, 于是我开始将topology, spout, bolt看成一个个bean, 然后放在spring容器中来完成初始化, 但是在本地模式运行的时候,
出现序列化的问题(抛出java.io.NotSerializableException异常), 以为是有些类忘记实现序列化接口了, 于是给相关类加上了序列化接口, 再跑, 还是抛java.io.NotSerializableException异常, 说另外一个依赖jar中的类需要实现序列化接口, 这个就麻烦了, 另外一个jar我没法修改代码, 我想可能是我哪些地方用的不对, 于是在group(http://groups.google.com/group/storm-user)中google之,
发现很多人都碰到了跟我类似的问题, 看了里面的讨论, 发现storm的作者Nathan Marz(http://nathanmarz.com)针对这个问题给出了合理的解释:
The lifecycle of a bolt or spout is as follows:
1. Created on client side (from where you submit the topology) and
serialized using Java serialization
2. Serialized component is sent to all the tasks
3. Each task executing that component deserializes the component
4. The task calls "prepare" (for bolts) or "open" (for spouts) on the
component before it starts executing.
So if you need to do something like connect to a database, you should do
that in the "prepare" or "open" method.
出现这个问题主要是对一个spout/bolt的生命周期不是很了解导致, 一般来说spout/bolt的生命周期如下:
1.在提交了一个topology之后(是在nimbus所在的机器么?), 创建spout/bolt实例(spout/bolt在storm中统称为component)并进行序列化.
2.将序列化的component发送给所有的任务所在的机器
3.在每一个任务上反序列化component.
4.在开始执行任务之前, 先执行component的初始化方法(bolt是prepare, spout是open).
因此component的初始化操作应该在prepare/open方法中进行, 而不是在实例化component的时候进行.
后来我又看了这篇文章"Twitter Storm源代码分析之Topology的执行过程(http://xumingming.sinaapp.com/647/twitter-storm-code-analysis-topology-execution/)", 不过里面没有提到Nathan所说的这些内容.
知道了上面的过程之后, 于是我开始改造我的代码, 那么该如何将storm与spring结合起来呢? 于是我又开始在group中google之, 发现有个韩国人写了一个storm-spring-example(https://github.com/mykidong/storm-spring-example),
于是下载下来研究了一番, 原来需要在每个spout/bolt维护自己的ApplicationConext, 于是将一个all in one 的spring打散成spring-spout.xml, spring-bolt-xxx.xml. 然后在open/prepare方法中加载对应的spring配置文件.
改造完成之后, 运行OK!
转载 :http://macrochen.iteye.com/blog/1408436
出现序列化的问题(抛出java.io.NotSerializableException异常), 以为是有些类忘记实现序列化接口了, 于是给相关类加上了序列化接口, 再跑, 还是抛java.io.NotSerializableException异常, 说另外一个依赖jar中的类需要实现序列化接口, 这个就麻烦了, 另外一个jar我没法修改代码, 我想可能是我哪些地方用的不对, 于是在group(http://groups.google.com/group/storm-user)中google之,
发现很多人都碰到了跟我类似的问题, 看了里面的讨论, 发现storm的作者Nathan Marz(http://nathanmarz.com)针对这个问题给出了合理的解释:
The lifecycle of a bolt or spout is as follows:
1. Created on client side (from where you submit the topology) and
serialized using Java serialization
2. Serialized component is sent to all the tasks
3. Each task executing that component deserializes the component
4. The task calls "prepare" (for bolts) or "open" (for spouts) on the
component before it starts executing.
So if you need to do something like connect to a database, you should do
that in the "prepare" or "open" method.
出现这个问题主要是对一个spout/bolt的生命周期不是很了解导致, 一般来说spout/bolt的生命周期如下:
1.在提交了一个topology之后(是在nimbus所在的机器么?), 创建spout/bolt实例(spout/bolt在storm中统称为component)并进行序列化.
2.将序列化的component发送给所有的任务所在的机器
3.在每一个任务上反序列化component.
4.在开始执行任务之前, 先执行component的初始化方法(bolt是prepare, spout是open).
因此component的初始化操作应该在prepare/open方法中进行, 而不是在实例化component的时候进行.
后来我又看了这篇文章"Twitter Storm源代码分析之Topology的执行过程(http://xumingming.sinaapp.com/647/twitter-storm-code-analysis-topology-execution/)", 不过里面没有提到Nathan所说的这些内容.
知道了上面的过程之后, 于是我开始改造我的代码, 那么该如何将storm与spring结合起来呢? 于是我又开始在group中google之, 发现有个韩国人写了一个storm-spring-example(https://github.com/mykidong/storm-spring-example),
于是下载下来研究了一番, 原来需要在每个spout/bolt维护自己的ApplicationConext, 于是将一个all in one 的spring打散成spring-spout.xml, spring-bolt-xxx.xml. 然后在open/prepare方法中加载对应的spring配置文件.
改造完成之后, 运行OK!
转载 :http://macrochen.iteye.com/blog/1408436
相关文章推荐
- storm组件初始化问题及与spring的结合方式
- struts2结合spring json序列化问题
- spring 和struts 的结合两种方式
- WebWork2.2中结合Spring:新的方式
- 序列化人人网框架下的DAO?也就是在Spring下序列化DAO的问题(spring+quartz集群下)
- Storm之trident序列化问题
- spring结合hibernate访问数据库方式的比较
- XFire与Spring结合的几种方式
- Storm之trident序列化问题
- spring结合quartz的定时的2种方式
- spring结合quartz的定时的2种方式
- unserialize的这个问题是由一个emlog论坛用户在使用时报错而发现的 问题表现情况如下: emlog缓存的保存方式是将php的数据对象(数组)序列化(serialize)后以文件的形式存放,
- 今天做hibernate和spring结合问题,
- SSI报空指针异常,即spring注入失败问题的解决方式
- spring结合quartz的定时的2种方式
- android结合SpringMVC 采用spring3.0版遇到的问题
- dwr结合spring例子及出现的相关问题
- Spring注解的方式注入bean时报异常bean找不到的问题
- struts2与spring 结合时一些问题
- xmemcached与spring结合使用时连接超时问题解决方法(转)