Commit 22a4e192 authored by liaozan's avatar liaozan 🏀

Update

parent eb32fd07
package com.schbrain.initializer.service;
/**
* @author liaozan
* @since 2023/11/27
*/
public interface StarrocksService {
boolean streamLoad(String tableName, Object content);
}
package com.schbrain.initializer.service.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author liaozan
* @since 2023/11/23
*/
@Data
@ConfigurationProperties(prefix = "starrocks")
public class StarrocksProperties {
private String feServerUrl = "schbrain-fe-svc.starrocks:8030";
}
package com.schbrain.initializer.service.impl;
import cn.hutool.http.HttpRequest;
import com.fasterxml.jackson.databind.JsonNode;
import com.schbrain.common.util.JacksonUtils;
import com.schbrain.initializer.service.StarrocksService;
import com.schbrain.initializer.service.config.StarrocksProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author liaozan
* @since 2023/11/27
*/
@Slf4j
@Service
public class StarrocksServiceImpl implements StarrocksService {
private static final String STREAM_LOAD_TEMPLATE = "http://%s/api/schbrain_mosaic/%s/_stream_load";
@Autowired
private StarrocksProperties starrocksProperties;
@Override
public boolean streamLoad(String tableName, Object content) {
String streamLoadUrl = getStreamLoadUrl(tableName);
String res = HttpRequest.put(streamLoadUrl)
.header("strict_mode", Boolean.TRUE.toString())
.header("Expect", "100-continue")
.header("format", "json")
.basicAuth("mosaic_admin", "schbrain111623")
.setFollowRedirects(true)
.body(JacksonUtils.toJsonString(content))
.execute()
.body();
System.out.println(res);
JsonNode loadResponse = JacksonUtils.getJsonNode(res);
log.info("stream load response: {}", loadResponse);
return true;
}
private String getStreamLoadUrl(String tableName) {
return String.format(STREAM_LOAD_TEMPLATE, starrocksProperties.getFeServerUrl(), tableName);
}
}
package com.schbrain.initializer; package com.schbrain.initializer;
import com.schbrain.initializer.service.StarrocksService;
import com.schbrain.initializer.service.config.StarrocksProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController @RestController
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties(StarrocksProperties.class)
public class Application { public class Application {
@Autowired
private StarrocksService starrocksService;
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
@GetMapping("/load")
public void doLoad() {
Map<String, String> content = Map.of("id", "1", "city", "name");
starrocksService.streamLoad("test", content);
}
} }
...@@ -15,6 +15,7 @@ import org.apache.commons.lang3.tuple.Triple; ...@@ -15,6 +15,7 @@ import org.apache.commons.lang3.tuple.Triple;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.*;
...@@ -32,6 +33,11 @@ public class EntityController { ...@@ -32,6 +33,11 @@ public class EntityController {
@Autowired @Autowired
private EntityWithLogicDeleteService entityWithLogicDeleteService; private EntityWithLogicDeleteService entityWithLogicDeleteService;
@GetMapping("/header")
public void printHeaders(HttpServletRequest request) {
request.getHeaderNames().asIterator().forEachRemaining(name -> log.info(name + ": " + request.getHeader(name)));
}
@GetMapping("/copy") @GetMapping("/copy")
public void copy() { public void copy() {
Entity entity = new Entity(); Entity entity = new Entity();
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<parent> <parent>
<groupId>com.schbrain.framework</groupId> <groupId>com.schbrain.framework</groupId>
<artifactId>schbrain-parent</artifactId> <artifactId>schbrain-parent</artifactId>
<version>3.0.9-SNAPSHOT</version> <version>3.0.11</version>
</parent> </parent>
<groupId>com.schbrain</groupId> <groupId>com.schbrain</groupId>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment