|
|
package com.yoho.datasync.consumer.handler.listener.community;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.datasync.consumer.common.EventEnum;
|
|
|
import com.yoho.datasync.consumer.handler.mqcomponent.AbstractMqListener;
|
|
|
import com.yoho.datasync.core.base.annotation.MqConsumerListerner;
|
|
|
import com.yoho.datasync.core.base.model.yh_community.UserInfo;
|
|
|
import org.elasticsearch.action.update.UpdateRequest;
|
|
|
import org.elasticsearch.action.update.UpdateResponse;
|
|
|
import org.elasticsearch.client.RequestOptions;
|
|
|
import org.elasticsearch.client.RestHighLevelClient;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
@Component
|
|
|
@MqConsumerListerner(dbName = "yh_community",tableName = "user_info")
|
|
|
public class UserInfoListener extends AbstractMqListener<UserInfo> {
|
...
|
...
|
@@ -15,13 +25,37 @@ public class UserInfoListener extends AbstractMqListener<UserInfo> { |
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UserInfoListener.class);
|
|
|
|
|
|
@Qualifier("rhlClient")
|
|
|
@Autowired
|
|
|
private RestHighLevelClient rhlClient;
|
|
|
|
|
|
@Override
|
|
|
protected void deleteData(UserInfo sourceObject , Object checkResult) throws Exception {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void updateData(UserInfo sourceObject , Object checkResult) throws Exception {
|
|
|
protected void updateData(UserInfo userInfo , Object checkResult) throws Exception {
|
|
|
//更新用户信息索引到ES
|
|
|
// 批量增加
|
|
|
UpdateRequest updateRequest = new UpdateRequest();
|
|
|
updateRequest.index("grass");
|
|
|
updateRequest.type("userInfo");
|
|
|
updateRequest.id(String.valueOf(userInfo.getYohoUid()));
|
|
|
updateRequest.doc(XContentFactory.jsonBuilder().startObject()
|
|
|
.field("nick_name", userInfo.getNickName())
|
|
|
.field("head_ico", userInfo.getHeadIco())
|
|
|
.field("yoho_uid", userInfo.getYohoUid())
|
|
|
.field("gender", userInfo.getGender())
|
|
|
.endObject());
|
|
|
|
|
|
try {
|
|
|
// 2 获取更新后的值
|
|
|
UpdateResponse indexResponse = rhlClient.update(updateRequest, RequestOptions.DEFAULT);
|
|
|
logger.info("updateIndex: {}" , JSON.toJSONString(indexResponse));
|
|
|
} catch (IOException e) {
|
|
|
logger.info("updateIndex error :{}" ,e);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -30,4 +64,5 @@ public class UserInfoListener extends AbstractMqListener<UserInfo> { |
|
|
protected EventEnum getEventReportEnum() {
|
|
|
return EventEnum.USER_INFO_UPDATE;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|