Переполнение есть

This commit is contained in:
2025-04-15 21:39:55 +03:00
parent 3245ffa10f
commit 9bd815aa7e
3 changed files with 60 additions and 7 deletions

View File

@@ -8,14 +8,29 @@ public class Send {
private static final String QUEUE_NAME = "hello";
public static void main(String[] args) throws Exception {
String delayEnv = System.getenv("PRODUCER_DELAY_MS");
int delay = delayEnv != null ? Integer.parseInt(delayEnv) : 1000;
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("rabbitmq");
try (Connection connection = factory.newConnection();
Channel channel = connection.createChannel()) {
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
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++;
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
Thread.sleep(delay);
}
}
}
}