https://www.rabbitmq.com/java-client.html
https://www.rabbitmq.com/java-client.html
amqp-client-5.10.0.jar
slf4j-api-1.7.30.jar
slf4j-simple-1.7.30.jar
public static void main(String[] args) {
String qname="demo";
Connection conn=null;
Channel chn=null;
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
factory.setPort(5672);
factory.setUsername("guest");
factory.setPassword("guest");
factory.setVirtualHost("/");
conn = factory.newConnection();
chn = conn.createChannel();
Consumer consumer = new DefaultConsumer(chn) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
String message = new String(body, "UTF-8");
System.out.println(envelope.getExchange() + "," + envelope.getRoutingKey() + "," + message);
}
};
// channel绑定队列,autoAck为true表示一旦收到消息则自动回复确认消息
chn.basicConsume(qname, true, consumer);
}catch(Exception ex){
System.out.println(ex);
}
}