Commit cc96837e authored by Mahesh Rohra's avatar Mahesh Rohra

Feign client

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