use of com.rabbitmq.client.DeliverCallback in project study-by-myself by Howinfun.
the class Receive1 method main.
public static void main(String[] args) throws Exception {
ConnectionFactory factory = ConnectionFactoryUtils.getFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(queueName, false, false, false, null);
channel.basicQos(1);
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
ThreadUtil.sleep(2, TimeUnit.SECONDS);
System.out.println(message);
// 是否批量提交
boolean multiple = false;
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), multiple);
};
boolean autoAck = false;
channel.basicConsume(queueName, autoAck, deliverCallback, consumerTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback in project study-by-myself by Howinfun.
the class InfoReceive method main.
@SneakyThrows
public static void main(String[] args) {
ConnectionFactory factory = ConnectionFactoryUtils.getFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(exchangeName, "topic");
channel.queueDeclare(queueName, false, false, false, null);
channel.queueBind(queueName, exchangeName, bindingKey);
DeliverCallback callback = (consumerTag, delivery) -> {
String msg = new String(delivery.getBody(), "utf-8");
System.out.println("接收到一条info消息:" + msg);
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 UserReceive method main.
@SneakyThrows
public static void main(String[] args) {
ConnectionFactory factory = ConnectionFactoryUtils.getFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(exchangeName, "topic");
channel.queueDeclare(queueName, false, false, false, null);
channel.queueBind(queueName, exchangeName, bindingKey);
DeliverCallback callBack = (consumerTag, delivery) -> {
String msg = new String(delivery.getBody(), "utf-8");
System.out.println("接收到一条user消息:" + msg);
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
};
channel.basicQos(1);
channel.basicConsume(queueName, false, callBack, consumerTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback in project force-oneself by Force-oneself.
the class ReceiveLogs method psReceive.
public void psReceive(String[] argv) throws Exception {
Channel channel = RabbitMQUtils.getChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, EXCHANGE_NAME, "");
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), StandardCharsets.UTF_8);
System.out.println(" [x] Received '" + message + "'");
};
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
});
}
use of com.rabbitmq.client.DeliverCallback in project force-oneself by Force-oneself.
the class ReceiveLogsDirect method main.
public static void main(String[] argv) throws Exception {
Channel channel = RabbitMQUtils.getChannel();
channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
String queueName = channel.queueDeclare().getQueue();
if (argv.length < 1) {
System.err.println("Usage: ReceiveLogsDirect [info] [warning] [error]");
System.exit(1);
}
for (String severity : argv) {
channel.queueBind(queueName, EXCHANGE_NAME, severity);
}
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), StandardCharsets.UTF_8);
System.out.println(" [x] Received '" + delivery.getEnvelope().getRoutingKey() + "':'" + message + "'");
};
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
});
}
Aggregations