TransactionalPublisher extends DiscretePublisher { @Override public void publish(Message message, DeliveryOptions deliveryOptions) throws IOException { publish(Collections.<Message>singletonList(message), deliveryOptions); } TransactionalPublisher(ConnectionFactory connectionFactory); @Override void publish(Message message, DeliveryOptions deliveryOptions); @Override void publish(List<Message> messages, DeliveryOptions deliveryOptions);  }
@Test public void shouldPublishMessageAndWaitForAck() throws Exception { Message message = new Message().exchange(TEST_EXCHANGE).routingKey(TEST_ROUTING_KEY); TransactionalPublisher publisher = new TransactionalPublisher(connectionFactory); mockConnectionOperations(); expect(channel.txSelect()).andReturn(null); expectLastCall().once(); channel.basicPublish(TEST_EXCHANGE, TEST_ROUTING_KEY, false, false, message.getBasicProperties(), message.getBodyContent()); expectLastCall().once(); expect(channel.txCommit()).andReturn(null); expectLastCall().once(); PowerMock.replayAll(); publisher.publish(message); PowerMock.verifyAll(); }