SUPPORT-8381: some changes
This commit is contained in:
parent
e2ae106b8a
commit
35dbbccf3e
3 changed files with 30 additions and 15 deletions
|
|
@ -4,5 +4,5 @@ package ervu.client.kafka;
|
|||
* @author Alexandr Shalaginov
|
||||
*/
|
||||
public interface KafkaClient {
|
||||
void sendMessage(String message);
|
||||
boolean sendMessage(String message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,21 +24,20 @@ public class KafkaClientImpl implements KafkaClient {
|
|||
this.kafkaTemplate = kafkaTemplate;
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
public boolean sendMessage(String message) {
|
||||
if (this.kafkaTopic == null) {
|
||||
throw new RuntimeException("Property kafka.send.topic is null");
|
||||
}
|
||||
ProducerRecord<String, String> record = new ProducerRecord<>("topic", message);
|
||||
|
||||
ListenableFuture<SendResult<String, String>> future = this.kafkaTemplate.send(record);
|
||||
future.addCallback(
|
||||
(result) -> {
|
||||
logger.debug("Success send message: {}", result);
|
||||
},
|
||||
(throwable) -> {
|
||||
logger.error("Fail send message.", throwable);
|
||||
}
|
||||
);
|
||||
ProducerRecord<String, String> record = new ProducerRecord<>(this.kafkaTopic, message);
|
||||
try {
|
||||
this.kafkaTemplate.send(record).get();
|
||||
logger.debug("Success send record: {}", record);
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception) {
|
||||
logger.error("Fail send message.", exception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,39 @@
|
|||
package ervu.service.fileupload.impl;
|
||||
|
||||
import ervu.client.fileupload.ErvuFileUploadClient;
|
||||
import ervu.client.kafka.KafkaClient;
|
||||
import ervu.service.fileupload.FileUploadV2Service;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import ru.cg.webbpm.modules.security.api.runtime.SecurityContext;
|
||||
|
||||
/**
|
||||
* @author Alexandr Shalaginov
|
||||
*/
|
||||
@Service
|
||||
public class ErvuFileUploadV2ServiceImpl implements FileUploadV2Service {
|
||||
private final KafkaClient kafkaClient;
|
||||
private final SecurityContext securityContext;
|
||||
private final ErvuFileUploadClient ervuFileUploadClient;
|
||||
|
||||
public ErvuFileUploadV2ServiceImpl(ErvuFileUploadClient ervuFileUploadClient) {
|
||||
public ErvuFileUploadV2ServiceImpl(ErvuFileUploadClient ervuFileUploadClient,
|
||||
KafkaClient kafkaClient,
|
||||
SecurityContext securityContext) {
|
||||
this.ervuFileUploadClient = ervuFileUploadClient;
|
||||
this.kafkaClient = kafkaClient;
|
||||
this.securityContext = securityContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveFile(MultipartFile multipartFile) {
|
||||
return this.ervuFileUploadClient.uploadFile(multipartFile);
|
||||
if (this.ervuFileUploadClient.uploadFile(multipartFile)) {
|
||||
String message = "{username='" + this.securityContext.getCurrentUsername()
|
||||
+ "',filename='" + multipartFile.getName() + "'}";
|
||||
return this.kafkaClient.sendMessage(message);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue