Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Move custom consumer from core services to utilities (#20)
Browse files Browse the repository at this point in the history
* Custom consumer mvn changes (#245)

* add new consumer

* Adding build config for egov-custom-consumer service

* added kafka host

* add client for financial signout

* Update CustomConsumerApplication.java

* Fixed serialization error in zuul

* [PBERP-456] - Extracted url to properties.

* Merging from old repo to new repo

* maven upgrade changes

* Jackson version and kafka issue fix

Co-authored-by: GhanshyamRawat <[email protected]>
Co-authored-by: sivaprakash123 <[email protected]>
Co-authored-by: venki <[email protected]>

* Merging from core services repo to utilities repo

* Adding custom consumer to build configuration

Co-authored-by: GhanshyamRawat <[email protected]>
Co-authored-by: sivaprakash123 <[email protected]>
Co-authored-by: venki <[email protected]>
  • Loading branch information
4 people authored Jul 20, 2020
1 parent 009661c commit 015d704
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 1 deletion.
9 changes: 8 additions & 1 deletion build/build-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ config:
build:
- work-dir: "data-upload"
image-name: "data-upload"
dockerfile: "build/maven/Dockerfile"
dockerfile: "build/maven/Dockerfile"

- name: "builds/utilities/egov-custom-consumer"
build:
- work-dir: "egov-custom-consumer"
image-name: "egov-custom-consumer"
dockerfile: "build/maven/Dockerfile"

11 changes: 11 additions & 0 deletions egov-custom-consumer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog
All notable changes to this module will be documented in this file.

## 1.1.0 - 2020-06-22

- Upgraded to `tracer:2.0.0-SNAPSHOT`
- Upgraded to `Spring boot 2.2.6`

## 1.0.0

- Base version
25 changes: 25 additions & 0 deletions egov-custom-consumer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM egovio/apline-jre:8u121-mdms-1.0

MAINTAINER Sivaprakash<[email protected]>


# INSTRUCTIONS ON HOW TO BUILD JAR:
# Move to the location where pom.xml is exist in project and build project using below command
# "mvn clean package"

#RUN cd /opt/mdms && git pull origin master

#RUN cd /opt && wget "https://codeload.github.com/egovernments/egov-mdms-data/zip/master" -O master.zip && unzip master.zip && rm -rf master.zip mdms && mv egov-mdms-data-master mdms

COPY /target/egov-custom-consumer-0.0.1-SNAPSHOT.jar /opt/egov/egov-custom-consumer.jar

COPY start.sh /usr/bin/start.sh

RUN chmod +x /usr/bin/start.sh

CMD ["/usr/bin/start.sh"]

# NOTE: the two 'RUN' commands can probably be combined inside of a single
# script (i.e. RUN build-and-install-app.sh) so that we can also clean up the
# extra files created during the `mvn package' command. that step inflates the
# resultant image by almost 1.0GB.
117 changes: 117 additions & 0 deletions egov-custom-consumer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.egov</groupId>
<artifactId>egov-custom-consumer</artifactId>
<version>1.1.0-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<commons-lang-version>2.6</commons-lang-version>
<maven.version>3.3.9</maven.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang-version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.egov.services</groupId>
<artifactId>tracer</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.egov.services</groupId>
<artifactId>services-common</artifactId>
<version>1.0.0-RELEASE</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.egovernments.org</id>
<name>eGov ERP Releases Repository</name>
<url>https://nexus-repo.egovernments.org/nexus/content/repositories/releases/</url>
</repository>
<repository>
<id>repo.egovernments.org.snapshots</id>
<name>eGov ERP Releases Repository</name>
<url>https://nexus-repo.egovernments.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>repo.egovernments.org.public</id>
<name>eGov Public Repository Group</name>
<url>https://nexus-repo.egovernments.org/nexus/content/groups/public/</url>
</repository>
</repositories>


<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.egov;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;

@SpringBootApplication
public class CustomConsumerApplication {

public static void main(String[] args) {
SpringApplication.run(CustomConsumerApplication.class, args);
}

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}

@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.egov.cosumer;

import java.util.HashMap;

import org.egov.service.SignOutService;
import org.egov.utils.JsonPathConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class CustomConsumer {

@Autowired
private SignOutService signOutService;

@Autowired
private ObjectMapper objectMapper;

@KafkaListener(topics = { "${egov.custom.async.filter.topic}" })
public void listen(final HashMap<String, Object> record, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {

log.info("CustomConsumer received request from topic: " + topic);
log.info("data: " + record);
log.info(record.keySet().toString());

try {
//String inputJson = objectMapper.writeValueAsString(record);
DocumentContext documentContext = JsonPath.parse(record);
String sourceUri = documentContext.read(JsonPathConstant.signOutUriJsonPath);

if(sourceUri.equals(JsonPathConstant.signOutUri))
signOutService.callFinanceForSignOut(documentContext);

} catch (Exception ex) {
ex.printStackTrace();
}

// ObjectMapper mapper = new ObjectMapper();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.egov.service;

import java.util.LinkedHashMap;

import org.egov.utils.JsonPathConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import com.jayway.jsonpath.DocumentContext;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class SignOutService {

@Autowired
private RestTemplate restTemplate;

@Value("${egov.coexistence.hostname}")
private String coexistencehost;

@Value("${egov.coexistence.singout.uri}")
private String coexistencelogoutUri;

public void callFinanceForSignOut(DocumentContext documentContext) {
ResponseEntity<?> response = null;
try {
;
String accessToken = documentContext.read(JsonPathConstant.signOutAccessToken);
documentContext = documentContext.delete(JsonPathConstant.userInfo);
documentContext = documentContext.put(JsonPathConstant.requestInfo, "authToken", accessToken);
LinkedHashMap<String, Object> jsonRequest = documentContext.read(JsonPathConstant.request);

response = restTemplate.exchange(coexistencehost + coexistencelogoutUri, HttpMethod.POST,
new HttpEntity<>(jsonRequest),
ResponseEntity.class);
log.info("SignOutService response :" + response.getStatusCode());
} catch (HttpClientErrorException ex) {
log.error(ex.getResponseBodyAsString());
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.egov.utils;

public class JsonPathConstant {

public static final String signOutAccessToken = "$.queryParamMap.access_token[0]";
public static final String request = "$.request";
public static final String userInfo = "$.request.RequestInfo.userInfo";
public static final String requestInfo = "$.request.RequestInfo";
public static final String accessTokenKey = "authToken";
public static final String signOutUri = "/user/_logout";
public static final String signOutUriJsonPath = "$.sourceUri";

}
15 changes: 15 additions & 0 deletions egov-custom-consumer/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spring.main.web-environment=false
server.context-path=/egov-custom-consumer
server.servlet.context-path=/egov-custom-consumer

# KAFKA SERVER CONFIGURATIONS
kafka.config.bootstrap_server_config=kafka-0.kafka.backbone:9092
spring.kafka.consumer.value-deserializer=org.egov.tracer.kafka.deserializer.HashMapDeserializer
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.group-id=egov-api-gateway-1

spring.kafka.listener.missing-topics-fatal=false

egov.custom.async.filter.topic=res-custom-filter
egov.coexistence.hostname=https://jalandhar-dev.egovernments.org
egov.coexistence.singout.uri=/services/EGF/rest/ClearToken
7 changes: 7 additions & 0 deletions egov-custom-consumer/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

if [[ -z "${JAVA_OPTS}" ]];then
export JAVA_OPTS="-Xmx64m -Xms64m"
fi

java ${JAVA_OPTS} -jar /opt/egov/egov-custom-consumer.jar

0 comments on commit 015d704

Please sign in to comment.