|
@@ -1,37 +1,52 @@
|
|
|
-/*
|
|
|
- * Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
- * contributor license agreements. See the NOTICE file distributed with
|
|
|
- * this work for additional information regarding copyright ownership.
|
|
|
- * The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
- * (the "License"); you may not use this file except in compliance with
|
|
|
- * the License. You may obtain a copy of the License at
|
|
|
- *
|
|
|
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
- *
|
|
|
- * Unless required by applicable law or agreed to in writing, software
|
|
|
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
- * See the License for the specific language governing permissions and
|
|
|
- * limitations under the License.
|
|
|
- */
|
|
|
package com.tzld.piaoquan.content.understanding.rocketmq.consumer;
|
|
|
|
|
|
-
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.tzld.piaoquan.content.understanding.service.ContentService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.rocketmq.client.annotation.RocketMQMessageListener;
|
|
|
import org.apache.rocketmq.client.apis.consumer.ConsumeResult;
|
|
|
import org.apache.rocketmq.client.apis.message.MessageView;
|
|
|
import org.apache.rocketmq.client.core.RocketMQListener;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.nio.ByteBuffer;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RocketMQMessageListener(endpoints = "${demo.trans.rocketmq.endpoints:}", topic = "${demo.trans.rocketmq.topic:}",
|
|
|
consumerGroup = "${demo.trans.rocketmq.consumer-group:}", tag = "${demo.trans.rocketmq.tag:}")
|
|
|
public class OldVersionRemainVideoUnderstandingConsumer implements RocketMQListener {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ContentService contentService;
|
|
|
+
|
|
|
@Override
|
|
|
public ConsumeResult consume(MessageView messageView) {
|
|
|
- System.out.println("handle my transaction message:" + messageView);
|
|
|
-
|
|
|
+ log.info("consume message = {}", messageView);
|
|
|
+ try {
|
|
|
+ ByteBuffer body = messageView.getBody();
|
|
|
+ Charset charset = StandardCharsets.UTF_8;
|
|
|
+ String message = charset.decode(body).toString();
|
|
|
+ Map<String, Object> messageMap = JSONObject.parseObject(message, new TypeReference<Map<String, Object>>() {});
|
|
|
+ Object videoIdObj = messageMap.get("videoId");
|
|
|
+ if (Objects.nonNull(videoIdObj)) {
|
|
|
+ Long videoId = Long.parseLong(videoIdObj.toString());
|
|
|
+ boolean flag = contentService.remainVideoUnderstandingHandler(videoId);
|
|
|
+ if (!flag) {
|
|
|
+ return ConsumeResult.FAILURE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("consume error {}", e, messageView);
|
|
|
+ return ConsumeResult.FAILURE;
|
|
|
+ }
|
|
|
return ConsumeResult.SUCCESS;
|
|
|
}
|
|
|
}
|