use of com.rabbitmq.client.DeliverCallback in project study-by-myself by Howinfun.
the class Receive2 method main.
public static void main(String[] args) throws IOException, TimeoutException {
ConnectionFactory factory = ConnectionFactoryUtils.getFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(exchangeName, "fanout");
channel.queueDeclare(queueName, false, false, false, null);
channel.queueBind(queueName, exchangeName, "");
DeliverCallback callback = (s, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
System.out.println(message);
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
};
channel.basicQos(1);
boolean autoAck = false;
channel.basicConsume(queueName, autoAck, callback, consumerTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback in project study-by-myself by Howinfun.
the class ErrorReceive method main.
public static void main(String[] args) throws Exception {
ConnectionFactory factory = ConnectionFactoryUtils.getFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
// 声明 exchange 和 queue
channel.exchangeDeclare(exchangeName, "direct");
channel.queueDeclare(queueName, false, false, false, null);
// 进行绑定
channel.queueBind(queueName, exchangeName, bindingKey);
channel.queueBind(queueName, exchangeName, bindingKey2);
DeliverCallback callback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "utf-8");
System.out.println("ErrorReceive 接收到" + delivery.getEnvelope().getRoutingKey() + "消息:" + message);
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
};
channel.basicQos(1);
channel.basicConsume(queueName, false, callback, consumerTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback in project study-by-myself by Howinfun.
the class Server method main.
public static void main(String[] args) throws Exception {
ConnectionFactory factory = ConnectionFactoryUtils.getFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(requestQueueName, false, false, false, null);
DeliverCallback callback = (consumerTag, delivery) -> {
String msg = new String(delivery.getBody(), "utf-8");
// 处理消息
String reponse = handleMsg(msg);
// 将消息的 correlationId 传回去
AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder().correlationId(delivery.getProperties().getCorrelationId()).build();
channel.basicPublish("", delivery.getProperties().getReplyTo(), replyProps, reponse.getBytes());
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
};
channel.basicQos(1);
channel.basicConsume(requestQueueName, false, callback, consumeTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback in project study-by-myself by Howinfun.
the class Receive12 method main.
public static void main(String[] args) throws IOException, TimeoutException {
ConnectionFactory factory = ConnectionFactoryUtils.getFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(exchangeName, "fanout");
channel.queueDeclare(queueName, false, false, false, null);
channel.queueBind(queueName, exchangeName, "");
DeliverCallback callback = (s, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
System.out.println(message);
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
};
channel.basicQos(1);
boolean autoAck = false;
channel.basicConsume(queueName, autoAck, callback, consumerTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback in project study-by-myself by Howinfun.
the class InfoReceive method main.
public static void main(String[] args) throws Exception {
ConnectionFactory factory = ConnectionFactoryUtils.getFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
// 声明 exchange 和 queue
channel.exchangeDeclare(exchangeName, "direct");
channel.queueDeclare(queueName, false, false, false, null);
// 进行绑定
channel.queueBind(queueName, exchangeName, bindingKey);
DeliverCallback callback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "utf-8");
System.out.println("ErrorReceive 接收到" + delivery.getEnvelope().getRoutingKey() + "消息:" + message);
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
};
channel.basicQos(1);
channel.basicConsume(queueName, false, callback, consumerTag -> {
});
}
Aggregations