尚硅谷大数据技术之电影推荐系统
(2019-09-18 09:41:58)
标签:
itjava培训linux大数据尚硅谷 |
分类: 大数据学科 |
5.3.5 更新实时推荐结果
当计算出候选电影的推荐优先级的数组updatedRecommends后,这个数组将被发送到Web 后台服务器,与后台服务器上userId 的上次实时推荐结果recentRecommends进行合并、替换并选出优先级E 前K大的电影作为本次新的实时推荐。具体而言:
a.合并:将updatedRecommends 与recentRecommends 并集合成为一个新的数组;
b.替换(去重):当updatedRecommends 与recentRecommends 有重复的电影movieId 时,recentRecommends 中movieId 的推荐优先级由于是上次实时推荐的结果,于是将作废,被替换成代表了更新后的updatedRecommends的movieId 的推荐优先级;
c.选取TopK:在合并、替换后的数组上,根据每个movie 的推荐优先级,选择出前K 大的电影,作为本次实时推荐的最终结果。
5.4 实时系统联调
我们的系统实时推荐的数据流向是:业务系统 -> 日志 -> flume 日志采集 -> kafka streaming数据清洗和预处理 -> spark streaming 流式计算。在我们完成实时推荐服务的代码后,应该与其它工具进行联调测试,确保系统正常运行。
5.4.1 启动实时系统的基本组件
启动实时推荐系统StreamingRecommender以及mongodb、redis
5.4.2 启动zookeeper
bin/zkServer.sh start
5.4.3 启动kafka
bin/kafka-server-start.sh -daemon ./config/server.properties
5.4.4 构建Kafka Streaming程序
在recommender下新建module,KafkaStreaming,主要用来做日志数据的预处理,过滤出需要的内容。pom.xml文件需要引入依赖:
<</span>dependencies>
<</span>dependency>
<</span>groupId>org.apache.kafka</</span>groupId>
<</span>artifactId>kafka-streams</</span>artifactId>
<</span>version>0.10.2.1</</span>version>
</</span>dependency>
<</span>dependency>
<</span>groupId>org.apache.kafka</</span>groupId>
<</span>artifactId>kafka-clients</</span>artifactId>
<</span>version>0.10.2.1</</span>version>
</</span>dependency>
</</span>dependencies>
<</span>build>
<</span>finalName>kafkastream</</span>finalName>
<</span>plugins>
<</span>plugin>
<</span>groupId>org.apache.maven.plugins</</span>groupId>
<</span>artifactId>maven-assembly-plugin</</span>artifactId>
<</span>configuration>
<</span>archive>
<</span>manifest>
<</span>mainClass>com.atguigu.kafkastream.Application</</span>mainClass>
</</span>manifest>
</</span>archive>
<</span>descriptorRefs>