Skip to content

Commit

Permalink
Merge pull request #58 from pankajjangid05/prod-development
Browse files Browse the repository at this point in the history
Prod development
  • Loading branch information
pankajjangid05 authored May 18, 2023
2 parents d937daf + 1a6e9e4 commit 45b5cec
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/com/uci/inbound/incoming/CampaignController.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ public class CampaignController {
@Value("${inbound-error}")
String topicFailure;

private long cassInsertCount;
private long cassInsertErrorCount;

@RequestMapping(value = "/start", method = RequestMethod.GET)
public ResponseEntity<String> startCampaign(@RequestParam("campaignId") String campaignId, @RequestParam(value = "page", required = false) String page) throws JsonProcessingException, JAXBException {
final long startTime = System.nanoTime();
logTimeTaken(startTime, 0, "process-start: %d ms");
log.info("Call campaign service : "+campaignId+" page : "+page);
Map<String, String> meta;
if(page != null && !page.isEmpty()){
Expand Down Expand Up @@ -100,8 +105,13 @@ public ResponseEntity<String> startCampaign(@RequestParam("campaignId") String c
XMessageDAO currentMessageToBeInserted = XMessageDAOUtils.convertXMessageToDAO(xmsg);
xMsgRepo.insert(currentMessageToBeInserted)
.doOnError(genericError("Error in inserting current message"))
.doOnSuccess(xMessageDAO -> {
cassInsertCount++;
log.info("Data insert in Cassandra Count : "+cassInsertCount);
})
.subscribe(xMessageDAO -> {
sendEventToKafka(xmsg);
logTimeTaken(startTime, 0, "process-end: %d ms");
});
}
);
Expand All @@ -120,10 +130,22 @@ private void sendEventToKafka(XMessage xmsg) {

private Consumer<Throwable> genericError(String s) {
return c -> {
cassInsertErrorCount++;
log.info("Data not inserted in Cassandra Count : " + cassInsertErrorCount);
log.error(s + "::" + c.getMessage());
};
}

private void logTimeTaken(long startTime, int checkpointID, String formatedMsg) {
long endTime = System.nanoTime();
long duration = (endTime - startTime) / 1000000;
if(formatedMsg == null) {
log.info(String.format("CP-%d: %d ms", checkpointID, duration));
} else {
log.info(String.format(formatedMsg, duration));
}
}

@RequestMapping(value = "/pause", method = RequestMethod.GET)
public void pauseCampaign(@RequestParam("campaignId") String campaignId) throws JsonProcessingException, JAXBException {
kafkaProducer.send(campaign, campaignId);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spring.data.cassandra.port=${CASSANDRA_PORT}
spring.data.cassandra.keyspace-name=${CASSANDRA_KEYSPACE}
spring.data.cassandra.local-datacenter=datacenter1
logging.level.root=INFO
logging.config=classpath:logback-spring.xml
spring.data.cassandra.request.timeout=12000000
spring.data.cassandra.connect-timeout-millis=1000000
spring.data.cassandra.read-timeout-millis=1000000
Expand Down
46 changes: 46 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<property name="LOGS" value="./logs" />

<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}:%line): %msg%n%throwable
</Pattern>
</layout>
</appender>

<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/spring-boot-logger.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p [%t] %C{1.}:%line %m%n</Pattern>
</encoder>

<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/inbound-log-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

<!-- LOG "com.baeldung*" at TRACE level -->
<logger name="com.baeldung" level="trace" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>

</configuration>

0 comments on commit 45b5cec

Please sign in to comment.