1.启动虚拟机rabbitmq后在浏览器输入
192.168.64.140:15672
可以进入登录界面。用户名和密码都是admin,登录后界面如下:
package m2;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;
public class Producer {
public static void main(String[] args) throws IOException, TimeoutException {
//连接
ConnectionFactory f = new ConnectionFactory();
f.setHost("192.168.64.140");
//f.setPort(5672);默认端口可以省略
f.setUsername("admin");
f.setPassword("admin");
Channel c = f.newConnection().createChannel();
//定义队列,创建队列,如果队列存在不会重复创建
c.queueDeclare("helloworld",false,false,false,null);
//发送消息
while (true){
System.out.println("输入消息:");
String s = new Scanner(System.in).nextLine();
c.basicPublish("","helloworld",null,s.getBytes());
}
}
}
在登录界面可以看到
![上传中...]()