Search in sources :

Example 16 with DeliverCallback

use of com.rabbitmq.client.DeliverCallback in project mercury by yellow013.

the class Recv method main.

public static void main(String[] args) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    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(QUEUE_NAME, true, deliverCallback, consumerTag -> {
    });
}
Also used : DeliverCallback(com.rabbitmq.client.DeliverCallback) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Connection(com.rabbitmq.client.Connection) Channel(com.rabbitmq.client.Channel) StandardCharsets(java.nio.charset.StandardCharsets) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) DeliverCallback(com.rabbitmq.client.DeliverCallback)

Example 17 with DeliverCallback

use of com.rabbitmq.client.DeliverCallback in project mercury by yellow013.

the class Worker method main.

public static void main(String[] args) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    final Connection connection = factory.newConnection();
    final Channel channel = connection.createChannel();
    channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
    channel.basicQos(1);
    DeliverCallback deliverCallback = (consumerTag, delivery) -> {
        String message = new String(delivery.getBody(), "UTF-8");
        System.out.println(" [x] Received '" + message + "'");
        try {
            doWork(message);
        } finally {
            System.out.println(" [x] Done");
            channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
        }
    };
    channel.basicConsume(TASK_QUEUE_NAME, false, deliverCallback, consumerTag -> {
    });
}
Also used : DeliverCallback(com.rabbitmq.client.DeliverCallback) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Connection(com.rabbitmq.client.Connection) Channel(com.rabbitmq.client.Channel) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) DeliverCallback(com.rabbitmq.client.DeliverCallback)

Example 18 with DeliverCallback

use of com.rabbitmq.client.DeliverCallback in project SpringBoot-Learning by kong0827.

the class consumer01 method main.

public static void main(String[] args) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("47.102.218.26");
    factory.setPort(5672);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(TOPIC_QUEUE_1, true, false, false, null);
    DeliverCallback deliverCallback = (consumerTag, delivery) -> {
        String message = new String(delivery.getBody(), "UTF-8");
        System.out.println(" message: " + message + "'");
    };
    channel.basicConsume(TOPIC_QUEUE_1, true, deliverCallback, consumerTag -> {
    });
}
Also used : DeliverCallback(com.rabbitmq.client.DeliverCallback) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Connection(com.rabbitmq.client.Connection) Channel(com.rabbitmq.client.Channel) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) DeliverCallback(com.rabbitmq.client.DeliverCallback)

Example 19 with DeliverCallback

use of com.rabbitmq.client.DeliverCallback in project study-by-myself by Howinfun.

the class Receive 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);
    DeliverCallback deliverCallback = (consumerTag, delivery) -> {
        String message = new String(delivery.getBody(), "UTF-8");
        System.out.println(message);
    };
    channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
    });
}
Also used : ConnectionFactoryUtils(com.hyf.testDemo.mq.ConnectionFactoryUtils) DeliverCallback(com.rabbitmq.client.DeliverCallback) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Connection(com.rabbitmq.client.Connection) Channel(com.rabbitmq.client.Channel) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) DeliverCallback(com.rabbitmq.client.DeliverCallback)

Example 20 with DeliverCallback

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 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 -> {
    });
}
Also used : ConnectionFactoryUtils(com.hyf.testDemo.mq.ConnectionFactoryUtils) DeliverCallback(com.rabbitmq.client.DeliverCallback) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Connection(com.rabbitmq.client.Connection) Channel(com.rabbitmq.client.Channel) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) DeliverCallback(com.rabbitmq.client.DeliverCallback)

Aggregations

DeliverCallback (com.rabbitmq.client.DeliverCallback)59 Channel (com.rabbitmq.client.Channel)58 Connection (com.rabbitmq.client.Connection)53 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)50 StandardCharsets (java.nio.charset.StandardCharsets)21 IOException (java.io.IOException)18 TimeoutException (java.util.concurrent.TimeoutException)12 ConnectionFactoryUtils (com.hyf.testDemo.mq.ConnectionFactoryUtils)11 AMQP (com.rabbitmq.client.AMQP)9 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6 Date (java.util.Date)5 RabbitMQUtils (com.quan.framework.amqp.util.RabbitMQUtils)4 CancelCallback (com.rabbitmq.client.CancelCallback)4 AbstractClient (ProducerDummy.Client.AbstractClient)3 AggregateMessage (ProducerDummy.Messages.AggregateMessage)2 Message (ProducerDummy.Messages.Message)2 ThreadUtil (cn.hutool.core.thread.ThreadUtil)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DeclareOk (com.rabbitmq.client.AMQP.Exchange.DeclareOk)2