This commit is contained in:
parent
1d33e0cd3b
commit
ed8b6dba91
14 changed files with 178 additions and 22 deletions
|
|
@ -37,6 +37,10 @@
|
|||
<groupId>ru.spcex.platform</groupId>
|
||||
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import ru.spcex.clearing.backendapi.config.element.BackendApiSettings;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
|
|
@ -25,11 +26,11 @@ public class BackEndApiImdgConfig {
|
|||
public ImdgProvider imdgProvider(
|
||||
@Qualifier("taskExecutorHazelcastClientInitializer") ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer,
|
||||
@Qualifier("taskExecutorIdGeneratorAwaiter") ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter,
|
||||
HazelcastSettings clientSetting
|
||||
BackendApiSettings clientSetting
|
||||
) {
|
||||
return new HazelcastService(taskExecutorHazelcastClientInitializer,
|
||||
taskExecutorIdGeneratorAwaiter,
|
||||
clientSetting);
|
||||
clientSetting.getHazelcast());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
|
||||
|
||||
@Component
|
||||
@PropertySource("file:${spring.config.location}/application.properties")
|
||||
@ConfigurationProperties("backend-api.hazelcast")
|
||||
public class HazelcastSettings extends HazelcastClientParams {
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.spcex.clearing.backendapi.config.element.BackendApiSettings;
|
||||
import ru.spcex.clearing.backendapi.config.element.KafkaSettings;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Configuration
|
||||
public class KafkaConfig {
|
||||
|
||||
@Autowired
|
||||
@Bean
|
||||
public Producer<String, String> createProducer(BackendApiSettings settings) {
|
||||
KafkaSettings kafkaSettings = settings.getKafka();
|
||||
Properties kafkaProps = new Properties();
|
||||
|
||||
//Assign localhost id
|
||||
kafkaProps.put("bootstrap.servers", kafkaSettings.getBootstrapServers());
|
||||
|
||||
//Set acknowledgements for producer requests.
|
||||
kafkaProps.put("acks", kafkaSettings.getAcks());
|
||||
|
||||
//If the request fails, the producer can automatically retry,
|
||||
kafkaProps.put("retries", kafkaSettings.getRetries());
|
||||
|
||||
//Specify buffer size in config
|
||||
kafkaProps.put("batch.size", kafkaSettings.getBatchSize());
|
||||
|
||||
//Reduce the no of requests less than 0
|
||||
kafkaProps.put("linger.ms", kafkaSettings.getLingerMs());
|
||||
//The buffer.memory controls the total amount of memory available to the producer for buffering.
|
||||
kafkaProps.put("buffer.memory", kafkaSettings.getBufferMemory());
|
||||
kafkaProps.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
|
||||
kafkaProps.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
|
||||
|
||||
return new KafkaProducer<>(kafkaProps);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,34 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
package ru.spcex.clearing.backendapi.config.element;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
|
||||
|
||||
@Component
|
||||
@PropertySource("file:${spring.config.location}/application.properties")
|
||||
@ConfigurationProperties("backend-api")
|
||||
public class BackendApiSettings {
|
||||
private HazelcastClientParams hazelcast;
|
||||
private KafkaSettings kafka;
|
||||
private String exampleSetting;
|
||||
|
||||
public HazelcastClientParams getHazelcast() {
|
||||
return hazelcast;
|
||||
}
|
||||
|
||||
public void setHazelcast(HazelcastClientParams hazelcast) {
|
||||
this.hazelcast = hazelcast;
|
||||
}
|
||||
|
||||
public KafkaSettings getKafka() {
|
||||
return kafka;
|
||||
}
|
||||
|
||||
public void setKafka(KafkaSettings kafka) {
|
||||
this.kafka = kafka;
|
||||
}
|
||||
|
||||
public String getExampleSetting() {
|
||||
return exampleSetting;
|
||||
}
|
||||
|
|
@ -15,6 +36,4 @@ public class BackendApiSettings {
|
|||
public void setExampleSetting(String exampleSetting) {
|
||||
this.exampleSetting = exampleSetting;
|
||||
}
|
||||
|
||||
private String exampleSetting;
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package ru.spcex.clearing.backendapi.config.element;
|
||||
|
||||
public class KafkaSettings {
|
||||
private String bootstrapServers;
|
||||
private String acks;
|
||||
private Integer retries;
|
||||
private Integer batchSize;
|
||||
private Integer lingerMs;
|
||||
private Integer bufferMemory;
|
||||
|
||||
public String getBootstrapServers() {
|
||||
return bootstrapServers;
|
||||
}
|
||||
|
||||
public void setBootstrapServers(String bootstrapServers) {
|
||||
this.bootstrapServers = bootstrapServers;
|
||||
}
|
||||
|
||||
public String getAcks() {
|
||||
return acks;
|
||||
}
|
||||
|
||||
public void setAcks(String acks) {
|
||||
this.acks = acks;
|
||||
}
|
||||
|
||||
public Integer getRetries() {
|
||||
return retries;
|
||||
}
|
||||
|
||||
public void setRetries(Integer retries) {
|
||||
this.retries = retries;
|
||||
}
|
||||
|
||||
public Integer getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
public void setBatchSize(Integer batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public Integer getLingerMs() {
|
||||
return lingerMs;
|
||||
}
|
||||
|
||||
public void setLingerMs(Integer lingerMs) {
|
||||
this.lingerMs = lingerMs;
|
||||
}
|
||||
|
||||
public Integer getBufferMemory() {
|
||||
return bufferMemory;
|
||||
}
|
||||
|
||||
public void setBufferMemory(Integer bufferMemory) {
|
||||
this.bufferMemory = bufferMemory;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,9 +9,9 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.spcex.clearing.backendapi.config.BackendApiSettings;
|
||||
import ru.spcex.clearing.backendapi.config.element.BackendApiSettings;
|
||||
|
||||
@Controller("/")
|
||||
@Controller
|
||||
public class DefaultController implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package ru.spcex.clearing.backendapi.controller.response;
|
||||
|
||||
public class BasicSpcexResponse {
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package ru.spcex.clearing.backendapi.controller;
|
||||
package ru.spcex.clearing.backendapi.security;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
|
@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import ru.spcex.clearing.backendapi.security.TokenRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
package ru.spcex.clearing.backendapi.security;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
|
|
@ -3,10 +3,18 @@ server.servlet.context-path=/backend-api
|
|||
spring.main.web-application-type=servlet
|
||||
|
||||
backend-api.example-setting=test
|
||||
|
||||
backend-api.hazelcast.cluster-members=127.0.0.1
|
||||
backend-api.hazelcast.login=dev
|
||||
backend-api.hazelcast.password=dev-pass
|
||||
|
||||
backend-api.kafka.bootstrap-servers=localhost:9092
|
||||
backend-api.kafka.acks=all
|
||||
backend-api.kafka.retries=0
|
||||
backend-api.kafka.batch-size=16384
|
||||
backend-api.kafka.linger-ms=1
|
||||
backend-api.kafka.buffer-memory=33554432
|
||||
|
||||
|
||||
##keycloak
|
||||
##keycloak.auth-server-url=http://10.200.200.147:8080/
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
backend-api.response.test1=This is response example 1.
|
||||
|
|
@ -0,0 +1 @@
|
|||
backend-api.response.test1=Это пример ответа 1.
|
||||
11
pom.xml
11
pom.xml
|
|
@ -38,6 +38,7 @@
|
|||
<external_libraries.hazelcast.version>3.12.4</external_libraries.hazelcast.version>
|
||||
<external_libraries.slf4j.version>1.7.33</external_libraries.slf4j.version>
|
||||
<external_libraries.logback.version>1.2.10</external_libraries.logback.version>
|
||||
<external_libraries.kafka.version>2.8.1</external_libraries.kafka.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
@ -110,6 +111,16 @@
|
|||
<artifactId>c3p0</artifactId>
|
||||
<version>0.9.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
<version>${external_libraries.kafka.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
<version>2.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue