1:项目背景
当一个app达到一定的体量,千人千面、个性化营销是每一个app提升留存、付费必备法宝。始终离不开营销利器,用户画像。项目从0到1构建画像体系,由T+1升级为实时。过程中不断的优化画像方案,赋能产品、业务。在个性化营销的路上越来越顺滑。
2:整体的技术方案
1:实时画像通过flink stream job
1: app上报log日志到springboot,springboot 处理相关逻辑到kafka 。
2: db binlog 通过maxwell 发送到kafka。
3:所有的日志都到kafka, 画像、推荐相关的服务不需要消费所有的event。所以需要做一次二次分流降低处理所有消息的压力。我们根据具体的业务场景,把对应需要消费的数据对应的topic配置在db中。flink通过双流join (broadcast) 处理配置信息。
4:项目中把埋点、binlog 分为两个实时流,两个流不操作任何存储。把需要同步的结果发送到kafka. 启动专门的画像同步流到hbase 或es。
5:补充说明一下,我们的画像体系要满足多个app的使用。所以一定需要一个id_mapping 服务。人与设备的关系,设备与人的关系(建议保存最近的两条)。推荐、画像相关的服务需要用到mapping关系。另外appstore也禁用idfa,用户重装、以后设备信息就会发生变化。
FlinkKafkaConsumer<Event> eventConsumer = new FlinkKafkaConsumer<>(Topics.TEST, new EventSchema(), kafkaConsumerProperties);
DataStreamSource<Event> eventStream = env.addSource(eventConsumer);
//创建规则
MapStateDescriptor<String, HashMap<String, HashSet<String>>> topicRulesBroadcastState = new MapStateDescriptor<>(
"topicRulesBroadcastState",
BasicTypeInfo.STRING_TYPE_INFO,
TypeInformation.of(new TypeHint<HashMap<String, HashSet<String>>>() {
}));
//EventRedistributeSource extends RichSourceFunction run method ,sleep 1-5分钟同步一次规则
DataStreamSource<List<TopicRedistribute>> topicInfo = env.addSource(new EventRedistributeSource());
BroadcastStream<List<TopicRedistribute>> broadcast = topicInfo.broadcast(topicRulesBroadcastState);
KeyedStream<EventResult, String> eventResultStringKeyedStream = eventStream.connect(broadcast).process(new EventRedistributeProcess(topicRulesBroadcastState)).
keyBy(new KeySelector<EventResult, String>() {
@Override
public String getKey(EventResult eventResult) throws Exception {
return eventResult.getTopic();
}
});
2:离线画像通过spark sql
1:所有的业务数据收集通过spark stre