Skip to content

Commit

Permalink
Fix for multiple chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
tppolkow committed Jul 24, 2019
1 parent ad2befa commit 392802b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/fydp/backend/controllers/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String welcome() {

@CrossOrigin(origins = "http://localhost:3000")
@GetMapping(value = ("/summaries"))
public List<String> getSummaries() {
public Map<String, String> getSummaries() {
logger.info("GET summary endpoint hit");

try {
Expand Down Expand Up @@ -154,7 +154,7 @@ public ChapterTextModel parseChapters(@RequestBody PdfInfo response) throws IOEx

chapterTextModel.setChpTextMap(chapterTxt);
for (Map.Entry entry : chapterTxt.entrySet()) {
producer.sendMessageWithKey(entry.getKey().toString(), entry.getValue().toString());
producer.sendMessageWithKey(entry.getValue().toString(), entry.getKey().toString());
}
listener.setMessages(chapterTxt.size());

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/fydp/backend/kafka/MessageListener.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
package com.fydp.backend.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

public class MessageListener {
private static final Logger logger = LoggerFactory.getLogger(MessageListener.class);

private CountDownLatch latch;

public List<String> messages;
public Map<String, String> messages;

public void setMessages(int numMessages){
latch = new CountDownLatch(numMessages);
messages = new ArrayList<>();
messages = new HashMap<>();
}

@KafkaListener(topics = "brevity_responses", groupId = KafkaConsumerConfig.groupId)
public void listen(String message){
logger.info("Received message : \n" + message);
messages.add(message);
public void listen(ConsumerRecord<String, String> record){

logger.info("Received message : \n" + record.key() + " : " + record.value());
messages.put(record.key(), record.value());
latch.countDown();
}

public List<String> getMessages() {
public Map<String, String> getMessages() {
return messages;
}

Expand Down

0 comments on commit 392802b

Please sign in to comment.