@Test public void testSyncSend() throws InterruptedException { int id = (int) (System.currentTimeMillis() / 1000); producer.syncSend(id); logger.info("[testSyncSend][发送编号：[{}] 发送成功]", id); new CountDownLatch(1).await(); }
public void syncSend(Integer id) { Demo13Message message = new Demo13Message(); message.setId(id); rabbitTemplate.invoke(new RabbitOperations.OperationsCallback<Object>() { @Override public Object doInRabbit(RabbitOperations operations) { operations.convertAndSend(Demo13Message.EXCHANGE, Demo13Message.ROUTING_KEY, message); logger.info("[doInRabbit][发送消息完成]"); operations.waitForConfirms(0); logger.info("[doInRabbit][等待 Confirm 完成]"); return null; } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 成功]"); } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 失败]"); } }); }
Demo13Producer { public void syncSend(Integer id) { Demo13Message message = new Demo13Message(); message.setId(id); rabbitTemplate.invoke(new RabbitOperations.OperationsCallback<Object>() { @Override public Object doInRabbit(RabbitOperations operations) { operations.convertAndSend(Demo13Message.EXCHANGE, Demo13Message.ROUTING_KEY, message); logger.info("[doInRabbit][发送消息完成]"); operations.waitForConfirms(0); logger.info("[doInRabbit][等待 Confirm 完成]"); return null; } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 成功]"); } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 失败]"); } }); } }
Demo13Producer { public void syncSend(Integer id) { Demo13Message message = new Demo13Message(); message.setId(id); rabbitTemplate.invoke(new RabbitOperations.OperationsCallback<Object>() { @Override public Object doInRabbit(RabbitOperations operations) { operations.convertAndSend(Demo13Message.EXCHANGE, Demo13Message.ROUTING_KEY, message); logger.info("[doInRabbit][发送消息完成]"); operations.waitForConfirms(0); logger.info("[doInRabbit][等待 Confirm 完成]"); return null; } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 成功]"); } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 失败]"); } }); }  }
Demo13Producer { public void syncSend(Integer id) { Demo13Message message = new Demo13Message(); message.setId(id); rabbitTemplate.invoke(new RabbitOperations.OperationsCallback<Object>() { @Override public Object doInRabbit(RabbitOperations operations) { operations.convertAndSend(Demo13Message.EXCHANGE, Demo13Message.ROUTING_KEY, message); logger.info("[doInRabbit][发送消息完成]"); operations.waitForConfirms(0); logger.info("[doInRabbit][等待 Confirm 完成]"); return null; } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 成功]"); } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 失败]"); } }); }  void syncSend(Integer id); }
Demo13Producer { public void syncSend(Integer id) { Demo13Message message = new Demo13Message(); message.setId(id); rabbitTemplate.invoke(new RabbitOperations.OperationsCallback<Object>() { @Override public Object doInRabbit(RabbitOperations operations) { operations.convertAndSend(Demo13Message.EXCHANGE, Demo13Message.ROUTING_KEY, message); logger.info("[doInRabbit][发送消息完成]"); operations.waitForConfirms(0); logger.info("[doInRabbit][等待 Confirm 完成]"); return null; } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 成功]"); } }, new ConfirmCallback() { @Override public void handle(long deliveryTag, boolean multiple) throws IOException { logger.info("[handle][Confirm 失败]"); } }); }  void syncSend(Integer id);  }