Skip to content

Commit fde4bc8

Browse files
committed
updated
1 parent fefbab1 commit fde4bc8

File tree

2 files changed

+35
-38
lines changed

2 files changed

+35
-38
lines changed

src/main/java/com/rabbit/test/handler/App.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,28 @@
1111
* Hello world!
1212
*
1313
*/
14-
public class App
15-
{
16-
private static Logger LOG = LogManager.getRootLogger();
14+
public class App {
1715

18-
private RabbitConnectionManager rabbitConnectionManager;
19-
public static void main( String[] args )
20-
{
21-
System.out.println( "Initializing Rabbit Request Handler" );
22-
(new App()).init();
16+
private static Logger LOG = LogManager.getRootLogger();
17+
private RabbitConnectionManager rcm;
18+
19+
public static void main(String[] args) throws InterruptedException{
20+
(new App()).initPro();
2321
}
24-
private void init(){
25-
rabbitConnectionManager = RabbitGateManager.getInstance().getRabbitConnectionManager();
26-
try {
27-
LOG.debug("waiting for five seconds...");
28-
Thread.sleep(5 * 1000);
29-
} catch (InterruptedException e) {
30-
// TODO Auto-generated catch block
31-
e.printStackTrace();
32-
}
22+
23+
public void initPro() throws InterruptedException {
24+
rcm = RabbitGateManager.getInstance().getRabbitConnectionManager();
25+
Thread.sleep(3000);
26+
27+
LOG.debug("rabbitConnectionManager is getting ready!");
3328
sleepUntilRabbitConnectionSucceed();
34-
LOG.info("Rabbit connection is ready now!");
29+
30+
LOG.debug("rabbitConnectionManager is ready to handle messages :D");
3531
}
36-
32+
3733
private void sleepUntilRabbitConnectionSucceed() {
3834
for (;;) {
39-
RabbitMessageConsumer rConsumer = rabbitConnectionManager
40-
.getRabbitMessageConsumer();
35+
RabbitMessageConsumer rConsumer = rcm.getRabbitMessageConsumer();
4136
if (rConsumer == null) {
4237
LOG.info("rConsumer is null. Rabbit connection is not ready yeat");
4338
try {
@@ -51,5 +46,5 @@ private void sleepUntilRabbitConnectionSucceed() {
5146
}
5247

5348
}
54-
49+
5550
}

src/main/java/com/rabbit/test/handler/rabbitmq/NlpProcessingRequestHandler.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.apache.logging.log4j.LogManager;
88
import org.apache.logging.log4j.Logger;
99

10-
import com.lacheff.commonutil.rabbitmq.RabbitGate;
1110
import com.lacheff.commonutil.rabbitmq.RabbitMessageHander;
1211
import com.lacheff.commonutil.rabbitmq.request.NlpProcessingRequest;
1312
import com.lacheff.commonutil.rabbitmq.request.NlpSummarizationRequest;
@@ -17,16 +16,11 @@
1716
import com.lacheff.commonutil.rabbitmq.support.RoutingKey;
1817

1918
public class NlpProcessingRequestHandler implements RabbitMessageHander {
20-
private static Logger LOG = LogManager.getLogger(NlpProcessingRequestHandler.class);
21-
22-
23-
24-
private RabbitGate rabbitGate = RabbitGateManager.getInstance().getRabbitGate();
19+
private static Logger LOG = LogManager.getRootLogger();
2520

2621
@Override
2722
public void handle(Object object) {
28-
LOG.info("Seeing this in the log means that message was send and received");
29-
23+
3024
if (object instanceof NlpProcessingRequest) {
3125
handleNlpProcessingRequest((NlpProcessingRequest) object);
3226
} else if (object instanceof NlpSummarizationRequest){
@@ -38,24 +32,32 @@ public void handle(Object object) {
3832
}
3933

4034
private void handleNlpProcessingRequest(NlpProcessingRequest nlpProcessingRequest) {
41-
LOG.info("Got processing request: {}", nlpProcessingRequest.getReviewUUID());
35+
LOG.info("[x] Got processing request: {}", nlpProcessingRequest);
4236
try {
4337

4438
NlpProcessingResponse nlpProcessingResponse = new NlpProcessingResponse();
45-
nlpProcessingResponse.setReviewUUID(new Date() + "");
46-
LOG.debug("Shipping response after NLP processing: {}", nlpProcessingResponse);
47-
rabbitGate.send(nlpProcessingResponse);
39+
nlpProcessingResponse.setReviewUUID(nlpProcessingRequest.getReviewUUID());
40+
41+
LOG.info("Shipping response after NLP processing: {}", nlpProcessingResponse);
42+
RabbitGateManager.getInstance().getRabbitGate().send(nlpProcessingResponse);
4843

4944
} catch (Exception ex) {
5045
LOG.error("Exception at handleNlpProcessingRequest:", ex);
5146
}
5247
}
5348

5449
private void handleNlpSummarizationRequest(NlpSummarizationRequest nlpSummarizationRequest){
55-
LOG.debug("Sending response after NLP Summarization Request");
56-
NlpSummarizationResponse nlpSummarizationResponse = new NlpSummarizationResponse();
57-
nlpSummarizationResponse.setRequestUUID(new Date() + "");
58-
rabbitGate.send(nlpSummarizationResponse);
50+
LOG.info("[x] Got nlpSummarization request: {}", nlpSummarizationRequest);
51+
try{
52+
NlpSummarizationResponse nlpSummarizationResponse = new NlpSummarizationResponse();
53+
nlpSummarizationResponse.setRequestUUID(new Date() + "");
54+
55+
LOG.info("Shipping response after NLP Summarization: {}", nlpSummarizationResponse);
56+
RabbitGateManager.getInstance().getRabbitGate().send(nlpSummarizationResponse);
57+
58+
} catch (Exception ex) {
59+
LOG.error("Exception at handleSummarizationRequest:", ex);
60+
}
5961
}
6062

6163
@Override

0 commit comments

Comments
 (0)