package com.sf.message.ack; import com.rabbitmq.client.Channel; import com.sf.util.RabbitMqUtils; import java.util.Scanner; public class Producer { private static String queueName = "hello1"; public static void main(String[] args) throws Exception { Channel channel = RabbitMqUtils.getChannel(); // 声明队列 channel.queueDeclare(queueName, false, false, false, null); System.out.println("输入消息:"); Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String message = scanner.next(); channel.basicPublish("", queueName, null, message.getBytes()); System.out.println("Producer send message : " + message); } } }