合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
~~~ public class Send { private final static String QUEUE_NAME = "simple_queue"; public static void main(String[] args) throws Exception { //获取连接 Connection connection = ConnectionUtil.getConn(); // 创建通道 Channel channel = connection.createChannel(); // 声明队列 channel.queueDeclare(QUEUE_NAME, false, false, false, null); // 向指定的队列中发送消息 String message = "hello rabbitmq"; channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); System.out.println("send message " +message); // 关闭通道和连接 channel.close(); connection.close(); } } ~~~