yumeng 3 dni temu
rodzic
commit
a0a0675a9d

+ 1 - 4
src/main/java/com/adx/tencent/honor/controller/HonorTrackingController.java

@@ -341,10 +341,7 @@ public class HonorTrackingController {
     }
 
     private void saveBlockedBid(HonorBidRecord record) {
-        if (coldStore == null) {
-            throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "honor cold store not configured");
-        }
-        coldStore.saveBid(record);
+        hotStore.recordBlockedBid(record);
     }
 
     private static Map<String, String> enrichMediaParams(Map<String, String> params, BaiduRtaDecision decision) {

+ 17 - 0
src/main/java/com/adx/tencent/honor/store/HonorHotStore.java

@@ -93,6 +93,23 @@ public class HonorHotStore {
         }
     }
 
+    public void recordBlockedBid(HonorBidRecord record) {
+        if (record.getCreatedAt() == null) record.setCreatedAt(Instant.now());
+        try {
+            String fullPayload = objectMapper.writeValueAsString(record);
+            redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
+                trimStreamIfNeeded(conn);
+                Map<byte[], byte[]> body = new LinkedHashMap<>();
+                body.put("type".getBytes(StandardCharsets.UTF_8), "bid".getBytes(StandardCharsets.UTF_8));
+                body.put("payload".getBytes(StandardCharsets.UTF_8), fullPayload.getBytes(StandardCharsets.UTF_8));
+                conn.streamCommands().xAdd(MapRecord.create(stream.getBytes(StandardCharsets.UTF_8), body));
+                return null;
+            });
+        } catch (Exception e) {
+            throw new RuntimeException("record blocked honor bid failed", e);
+        }
+    }
+
     public void recordTracking(HonorTrackingRecord record) {
         if (record.getCreatedAt() == null) record.setCreatedAt(Instant.now());
         try {

+ 6 - 2
src/main/java/com/adx/tencent/oppo/controller/OppoTrackingController.java

@@ -69,7 +69,7 @@ public class OppoTrackingController {
         Map<String, String> rtaParams = enrichMediaParams(p, rtaDecision);
         if (!rtaDecision.allowsBid()) {
             OppoBidRecord blocked = blockedBidRecord(trace, "impression", rtaParams, rtaDecision);
-            store.recordBid(blocked);
+            saveBlockedBid(blocked);
             return responseBody(rtaParams, blocked.getQk(), trace, blocked.getTagId(), rtaDecision);
         }
         NormalizedBidResponse response = adx.requestBid("oppo", trace, buildBidRequest(request, trace, rtaParams));
@@ -93,7 +93,7 @@ public class OppoTrackingController {
             Map<String, String> rtaParams = enrichMediaParams(p, rtaDecision);
             if (!rtaDecision.allowsBid()) {
                 OppoBidRecord blocked = blockedBidRecord(trace, "click", rtaParams, rtaDecision);
-                store.recordBid(blocked);
+                saveBlockedBid(blocked);
                 return responseBody(rtaParams, blocked.getQk(), trace, blocked.getTagId(), rtaDecision);
             }
             NormalizedBidResponse bid = adx.requestBid("oppo", trace, buildBidRequest(request, trace, rtaParams));
@@ -201,6 +201,10 @@ public class OppoTrackingController {
         return enriched;
     }
 
+    private void saveBlockedBid(OppoBidRecord record) {
+        store.recordBlockedBid(record);
+    }
+
     private static Map<String, Object> responseBody(Map<String, String> params,
                                                     String qk,
                                                     String trace,

+ 17 - 0
src/main/java/com/adx/tencent/oppo/store/OppoHotStore.java

@@ -99,6 +99,23 @@ public class OppoHotStore {
         }
     }
 
+    public void recordBlockedBid(OppoBidRecord record) {
+        if (record.getCreatedAt() == null) record.setCreatedAt(Instant.now());
+        try {
+            String fullPayload = objectMapper.writeValueAsString(record);
+            redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
+                trimStreamIfNeeded(conn);
+                Map<byte[], byte[]> body = new LinkedHashMap<>();
+                body.put("type".getBytes(StandardCharsets.UTF_8), "bid".getBytes(StandardCharsets.UTF_8));
+                body.put("payload".getBytes(StandardCharsets.UTF_8), fullPayload.getBytes(StandardCharsets.UTF_8));
+                conn.streamCommands().xAdd(MapRecord.create(stream.getBytes(StandardCharsets.UTF_8), body));
+                return null;
+            });
+        } catch (Exception e) {
+            throw new RuntimeException("record blocked oppo bid failed", e);
+        }
+    }
+
     public void recordTracking(OppoTrackingRecord record) {
         if (record.getCreatedAt() == null) record.setCreatedAt(Instant.now());
         try {

+ 1 - 4
src/main/java/com/adx/tencent/vivo/controller/VivoTrackingController.java

@@ -413,10 +413,7 @@ public class VivoTrackingController {
     }
 
     private void saveBlockedBid(VivoBidRecord record) {
-        if (coldStore == null) {
-            throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "vivo cold store not configured");
-        }
-        coldStore.saveBid(record);
+        hotStore.recordBlockedBid(record);
     }
 
     private static Map<String, String> enrichMediaParams(Map<String, String> params, BaiduRtaDecision decision) {

+ 17 - 0
src/main/java/com/adx/tencent/vivo/store/VivoHotStore.java

@@ -98,6 +98,23 @@ public class VivoHotStore {
         }
     }
 
+    public void recordBlockedBid(VivoBidRecord record) {
+        if (record.getCreatedAt() == null) record.setCreatedAt(Instant.now());
+        try {
+            String fullPayload = objectMapper.writeValueAsString(record);
+            redis.executePipelined((org.springframework.data.redis.connection.RedisConnection conn) -> {
+                trimStreamIfNeeded(conn);
+                Map<byte[], byte[]> body = new LinkedHashMap<>();
+                body.put("type".getBytes(StandardCharsets.UTF_8), "bid".getBytes(StandardCharsets.UTF_8));
+                body.put("payload".getBytes(StandardCharsets.UTF_8), fullPayload.getBytes(StandardCharsets.UTF_8));
+                conn.streamCommands().xAdd(MapRecord.create(stream.getBytes(StandardCharsets.UTF_8), body));
+                return null;
+            });
+        } catch (Exception e) {
+            throw new RuntimeException("record blocked vivo bid failed", e);
+        }
+    }
+
     public void recordTracking(VivoTrackingRecord record) {
         if (record.getCreatedAt() == null) record.setCreatedAt(Instant.now());
         try {