@Test @SneakyThrows public void process() { Thread.sleep(1 * 1000); Executors.newSingleThreadScheduledExecutor() .scheduleAtFixedRate( this::send, 0, 3, TimeUnit.SECONDS); Thread.sleep(12 * 1000); }
@SneakyThrows @RabbitListener(bindings = @QueueBinding( exchange = @Exchange(value = RabbitMQConstant.CONFIRM_EXCHANGE, type = ExchangeTypes.TOPIC, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), value = @Queue(value = RabbitMQConstant.CONFIRM_QUEUE, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), key = RabbitMQConstant.CONFIRM_KEY), containerFactory = "containerWithConfirm") public void process(ExampleEvent msg, Channel channel, @Header(name = "amqp_deliveryTag") long deliveryTag, @Header("amqp_redelivered") boolean redelivered, @Headers Map<String, String> head) { try { log.info("ConsumerWithConfirm receive message:{},header:{}", msg, head); channel.basicAck(deliveryTag, false); } catch (Exception e) { log.error("consume confirm error!", e); channel.basicReject(deliveryTag, !redelivered); } }
ConsumerWithConfirm { @SneakyThrows @RabbitListener(bindings = @QueueBinding( exchange = @Exchange(value = RabbitMQConstant.CONFIRM_EXCHANGE, type = ExchangeTypes.TOPIC, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), value = @Queue(value = RabbitMQConstant.CONFIRM_QUEUE, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), key = RabbitMQConstant.CONFIRM_KEY), containerFactory = "containerWithConfirm") public void process(ExampleEvent msg, Channel channel, @Header(name = "amqp_deliveryTag") long deliveryTag, @Header("amqp_redelivered") boolean redelivered, @Headers Map<String, String> head) { try { log.info("ConsumerWithConfirm receive message:{},header:{}", msg, head); channel.basicAck(deliveryTag, false); } catch (Exception e) { log.error("consume confirm error!", e); channel.basicReject(deliveryTag, !redelivered); } } }
ConsumerWithConfirm { @SneakyThrows @RabbitListener(bindings = @QueueBinding( exchange = @Exchange(value = RabbitMQConstant.CONFIRM_EXCHANGE, type = ExchangeTypes.TOPIC, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), value = @Queue(value = RabbitMQConstant.CONFIRM_QUEUE, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), key = RabbitMQConstant.CONFIRM_KEY), containerFactory = "containerWithConfirm") public void process(ExampleEvent msg, Channel channel, @Header(name = "amqp_deliveryTag") long deliveryTag, @Header("amqp_redelivered") boolean redelivered, @Headers Map<String, String> head) { try { log.info("ConsumerWithConfirm receive message:{},header:{}", msg, head); channel.basicAck(deliveryTag, false); } catch (Exception e) { log.error("consume confirm error!", e); channel.basicReject(deliveryTag, !redelivered); } }  }
ConsumerWithConfirm { @SneakyThrows @RabbitListener(bindings = @QueueBinding( exchange = @Exchange(value = RabbitMQConstant.CONFIRM_EXCHANGE, type = ExchangeTypes.TOPIC, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), value = @Queue(value = RabbitMQConstant.CONFIRM_QUEUE, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), key = RabbitMQConstant.CONFIRM_KEY), containerFactory = "containerWithConfirm") public void process(ExampleEvent msg, Channel channel, @Header(name = "amqp_deliveryTag") long deliveryTag, @Header("amqp_redelivered") boolean redelivered, @Headers Map<String, String> head) { try { log.info("ConsumerWithConfirm receive message:{},header:{}", msg, head); channel.basicAck(deliveryTag, false); } catch (Exception e) { log.error("consume confirm error!", e); channel.basicReject(deliveryTag, !redelivered); } }  @SneakyThrows @RabbitListener(bindings = @QueueBinding( exchange = @Exchange(value = RabbitMQConstant.CONFIRM_EXCHANGE, type = ExchangeTypes.TOPIC, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), value = @Queue(value = RabbitMQConstant.CONFIRM_QUEUE, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), key = RabbitMQConstant.CONFIRM_KEY), containerFactory = "containerWithConfirm") void process(ExampleEvent msg, Channel channel, @Header(name = "amqp_deliveryTag") long deliveryTag,
                        @Header("amqp_redelivered") boolean redelivered, @Headers Map<String, String> head); }
ConsumerWithConfirm { @SneakyThrows @RabbitListener(bindings = @QueueBinding( exchange = @Exchange(value = RabbitMQConstant.CONFIRM_EXCHANGE, type = ExchangeTypes.TOPIC, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), value = @Queue(value = RabbitMQConstant.CONFIRM_QUEUE, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), key = RabbitMQConstant.CONFIRM_KEY), containerFactory = "containerWithConfirm") public void process(ExampleEvent msg, Channel channel, @Header(name = "amqp_deliveryTag") long deliveryTag, @Header("amqp_redelivered") boolean redelivered, @Headers Map<String, String> head) { try { log.info("ConsumerWithConfirm receive message:{},header:{}", msg, head); channel.basicAck(deliveryTag, false); } catch (Exception e) { log.error("consume confirm error!", e); channel.basicReject(deliveryTag, !redelivered); } }  @SneakyThrows @RabbitListener(bindings = @QueueBinding( exchange = @Exchange(value = RabbitMQConstant.CONFIRM_EXCHANGE, type = ExchangeTypes.TOPIC, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), value = @Queue(value = RabbitMQConstant.CONFIRM_QUEUE, durable = RabbitMQConstant.FALSE_CONSTANT, autoDelete = RabbitMQConstant.TURE_CONSTANT), key = RabbitMQConstant.CONFIRM_KEY), containerFactory = "containerWithConfirm") void process(ExampleEvent msg, Channel channel, @Header(name = "amqp_deliveryTag") long deliveryTag,
                        @Header("amqp_redelivered") boolean redelivered, @Headers Map<String, String> head);  }