#502 Replaced usages of System.out with logger.
This commit is contained in:
@ -23,11 +23,15 @@
|
||||
package com.iluwatar.poison.pill;
|
||||
|
||||
import com.iluwatar.poison.pill.Message.Headers;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Class responsible for receiving and handling submitted to the queue messages
|
||||
*/
|
||||
public class Consumer {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Consumer.class);
|
||||
|
||||
private final MqSubscribePoint queue;
|
||||
private final String name;
|
||||
@ -46,19 +50,18 @@ public class Consumer {
|
||||
try {
|
||||
msg = queue.take();
|
||||
if (Message.POISON_PILL.equals(msg)) {
|
||||
System.out.println(String.format("Consumer %s receive request to terminate.", name));
|
||||
LOGGER.info("Consumer {} receive request to terminate.", name);
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// allow thread to exit
|
||||
System.err.println(e);
|
||||
LOGGER.error("Exception caught.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
String sender = msg.getHeader(Headers.SENDER);
|
||||
String body = msg.getBody();
|
||||
System.out.println(String.format("Message [%s] from [%s] received by [%s]", body, sender,
|
||||
name));
|
||||
LOGGER.info("Message [{}] from [{}] received by [{}]", body, sender, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ package com.iluwatar.poison.pill;
|
||||
import java.util.Date;
|
||||
|
||||
import com.iluwatar.poison.pill.Message.Headers;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Class responsible for producing unit of work that can be expressed as message and submitted to
|
||||
@ -32,6 +34,8 @@ import com.iluwatar.poison.pill.Message.Headers;
|
||||
*/
|
||||
public class Producer {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Producer.class);
|
||||
|
||||
private final MqPublishPoint queue;
|
||||
private final String name;
|
||||
private boolean isStopped;
|
||||
@ -62,7 +66,7 @@ public class Producer {
|
||||
queue.put(msg);
|
||||
} catch (InterruptedException e) {
|
||||
// allow thread to exit
|
||||
System.err.println(e);
|
||||
LOGGER.error("Exception caught.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +79,7 @@ public class Producer {
|
||||
queue.put(Message.POISON_PILL);
|
||||
} catch (InterruptedException e) {
|
||||
// allow thread to exit
|
||||
System.err.println(e);
|
||||
LOGGER.error("Exception caught.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user