mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-06-08 14:12:51 +00:00
Reformat rest of the design patterns - Issue #224
This commit is contained in:
@@ -7,32 +7,33 @@ import com.iluwatar.poison.pill.Message.Headers;
|
||||
*/
|
||||
public class Consumer {
|
||||
|
||||
private final MQSubscribePoint queue;
|
||||
private final String name;
|
||||
private final MQSubscribePoint queue;
|
||||
private final String name;
|
||||
|
||||
public Consumer(String name, MQSubscribePoint queue) {
|
||||
this.name = name;
|
||||
this.queue = queue;
|
||||
}
|
||||
public Consumer(String name, MQSubscribePoint queue) {
|
||||
this.name = name;
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public void consume() {
|
||||
while (true) {
|
||||
Message msg;
|
||||
try {
|
||||
msg = queue.take();
|
||||
if (msg == Message.POISON_PILL) {
|
||||
System.out.println(String.format("Consumer %s receive request to terminate.", name));
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// allow thread to exit
|
||||
System.err.println(e);
|
||||
return;
|
||||
}
|
||||
public void consume() {
|
||||
while (true) {
|
||||
Message msg;
|
||||
try {
|
||||
msg = queue.take();
|
||||
if (msg == Message.POISON_PILL) {
|
||||
System.out.println(String.format("Consumer %s receive request to terminate.", name));
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// allow thread to exit
|
||||
System.err.println(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));
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user