Commit cc96837e authored by Mahesh Rohra's avatar Mahesh Rohra

Feign client

parent 2a2fa55b
......@@ -6,7 +6,7 @@ plugins {
group = 'com.safeway.epe'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
sourceCompatibility = '11'
configurations {
developmentOnly
......@@ -27,7 +27,6 @@ repositories {
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
......
......@@ -3,13 +3,7 @@ package com.safeway.epe.Config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.client.RootUriTemplateHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriTemplateHandler;
@Data
@Configuration
......@@ -17,22 +11,7 @@ import org.springframework.web.util.UriTemplateHandler;
public class ConfigProps {
private String offerTransactionRecordTopic;
@Value("${schema.api.baseurl}")
private String schemaBaseUrl;
private static final String USER_AGENT = "Producer";
private static final String APPLICATION_KAFKA_JSON_VALUE = "application/vnd.kafka.json.v2+json";
private static final String ACCEPT_APPLICATION_KAFKA_JSON_VALUE = "application/vnd.kafka.v2+json";
@Bean
RestTemplate restTemplate(RestTemplateBuilder builder) {
UriTemplateHandler uriTemplateHandler = new RootUriTemplateHandler(schemaBaseUrl);
return builder
.uriTemplateHandler(uriTemplateHandler)
.defaultHeader(HttpHeaders.USER_AGENT, USER_AGENT)
.defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_KAFKA_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, ACCEPT_APPLICATION_KAFKA_JSON_VALUE)
.build();
}
}
......@@ -8,14 +8,12 @@ import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = "service", url = "localhost:8082")
//@Headers({"User-Agent:Producer","Content-Type:application/vnd.kafka.json.v2+json","Accept:application/vnd.kafka.v2+json"})
@FeignClient(name = "service", url = "${schema.api.baseurl}")
@Headers({"User-Agent:Producer","Accept:application/vnd.kafka.v2+json"})
public interface ProducerServiceProxy
{
@RequestMapping(method= RequestMethod.POST, value="topics/{topic}", consumes = "application/vnd.kafka.json.v2+json")
@PostMapping(value="topics/{topic}", consumes = "application/vnd.kafka.json.v2+json")
ResponseEntity<ConsumerPayload> produceTransactionService(@PathVariable("topic") String topic,
@RequestBody TransactionPayload transactionPayload,
@RequestHeader("Accept") String accept,
//@RequestHeader("Content-Type") String contentType,
@RequestHeader("User-Agent") String useAgent);
@RequestBody TransactionPayload transactionPayload);
}
......@@ -33,16 +33,10 @@ public class TransactionRecorder
@Column(name = "uuid")
@JsonProperty("uuid")
UUID uuid;
// @Type(type = "jsonb")
// @JsonProperty("offertransactionresponse")
@Column(name = "offertransactionresponse")
String offerTransactionResponse;
// @Type(type="jsonb")
// @JsonProperty("offers")
@Column(name="offers")
String offers;
@Column(name="isprocessed")
boolean isProcessed;
}
......@@ -10,9 +10,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.List;
import java.util.function.Consumer;
@Component
public class ProducerService
......@@ -22,21 +20,13 @@ public class ProducerService
@Autowired
private TransactionService transactionService;
@Autowired
private RestTemplate restTemplate;
@Autowired
private ProducerServiceProxy producerServiceProxy;
public List<Offsets> produce(TransactionPayload request, String topic, TransactionRecorder transactionRecorder, boolean isReprocesed)
{
//new
ResponseEntity<ConsumerPayload> response = producerServiceProxy.produceTransactionService(topic,request,"application/vnd.kafka.v2+json","producer");
//String topicUri = "/topics/".concat(topic);
//ResponseEntity<ConsumerPayload> response = restTemplate.postForEntity(topicUri, request, ConsumerPayload.class);
logger.info("response ::response ::" + response);
ResponseEntity<ConsumerPayload> response = producerServiceProxy.produceTransactionService(topic,request);
logger.info("response ::" + response);
if(response != null && (response.getStatusCodeValue() == 200 || response.getStatusCode().is2xxSuccessful()))
{
......
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