Producers names
This commit is contained in:
@@ -17,6 +17,7 @@ services:
|
||||
- rabbitmq
|
||||
- consumer
|
||||
environment:
|
||||
- PRODUCER_NAME=first
|
||||
- PRODUCER_DELAY_MS=1000
|
||||
networks:
|
||||
- rabbitnet
|
||||
@@ -29,6 +30,7 @@ services:
|
||||
- rabbitmq
|
||||
- consumer
|
||||
environment:
|
||||
- PRODUCER_NAME=second
|
||||
- PRODUCER_DELAY_MS=1000
|
||||
networks:
|
||||
- rabbitnet
|
||||
|
||||
@@ -8,6 +8,9 @@ public class Send {
|
||||
private static final String QUEUE_NAME = "hello";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String name = System.getenv("PRODUCER_NAME");
|
||||
name = name != null ? name : "";
|
||||
|
||||
String delayEnv = System.getenv("PRODUCER_DELAY_MS");
|
||||
int delay = delayEnv != null ? Integer.parseInt(delayEnv) : 1000;
|
||||
|
||||
@@ -16,17 +19,11 @@ public class Send {
|
||||
|
||||
try (Connection connection = factory.newConnection();
|
||||
Channel channel = connection.createChannel()) {
|
||||
|
||||
boolean durable = false;
|
||||
boolean exclusive = false;
|
||||
boolean autoDelete = false;
|
||||
|
||||
// channel.queueDeclare(QUEUE_NAME, durable, exclusive, autoDelete, null);
|
||||
channel.queueDeclarePassive(QUEUE_NAME);
|
||||
|
||||
int count = 0;
|
||||
while (true) {
|
||||
String message = "Message #" + count++;
|
||||
String message = "Message from " + name + " #" + count++;
|
||||
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
|
||||
System.out.println(" [x] Sent '" + message + "'");
|
||||
Thread.sleep(delay);
|
||||
|
||||
Reference in New Issue
Block a user