ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); String queueName = "appsensor_queue"; channel.queueDeclare(queueName, false, false, false, null); String message = "Hello, RabbitMQ!"; channel.basicPublish("", queueName, null, message.getBytes("UTF-8")); boolean autoAck = true; Consumer consumer = new DefaultConsumer(channel) { @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("Received message: " + message); } }; channel.basicConsume(queueName, autoAck, consumer);


上一篇:
下一篇:
切换中文