Source:
public void test() { CachingConnectionFactory ccf = new CachingConnectionFactory("localhost"); RabbitTemplate template = new RabbitTemplate(ccf); RabbitAdmin admin = new RabbitAdmin(ccf); FanoutExchange fanout = new FanoutExchange("log4j2Test"); admin.declareExchange(fanout); Queue queue = new Queue("log4j2Test"); admin.declareQueue(queue); admin.declareBinding(BindingBuilder.bind(queue).to(fanout)); Logger logger = LogManager.getLogger("foo"); logger.info("foo"); logger.info("bar"); template.setReceiveTimeout(10000); Message received = template.receive(queue.getName()); assertThat(received).isNotNull(); assertThat(received.getMessageProperties().getReceivedRoutingKey()).isEqualTo("testAppId.foo.INFO"); Object foo = received.getMessageProperties().getHeader("foo"); assertThat(foo).isNotNull(); assertThat(foo).isInstanceOf(String.class); assertThat(foo).isEqualTo("bar"); assertThat(new String(received.getBody())).startsWith("foo"); received = template.receive(queue.getName()); assertThat(received).isNotNull(); assertThat(received.getMessageProperties().getReceivedRoutingKey()).isEqualTo("testAppId.foo.INFO"); assertThat(new String(received.getBody())).startsWith("bar"); Object threadName = received.getMessageProperties().getHeaders().get("thread"); assertThat(threadName).isNotNull(); assertThat(threadName).isInstanceOf(String.class); assertThat(threadName).isEqualTo(Thread.currentThread().getName()); foo = received.getMessageProperties().getHeaders().get("foo"); assertThat(foo).isNotNull(); assertThat(foo).isInstanceOf(String.class); assertThat(foo).isEqualTo("bar"); }

Target:
public void test() { CachingConnectionFactory ccf = new CachingConnectionFactory("localhost"); RabbitTemplate template = new RabbitTemplate(ccf); RabbitAdmin admin = new RabbitAdmin(ccf); FanoutExchange fanout = new FanoutExchange("log4j2Test"); admin.declareExchange(fanout); Queue queue = new Queue("log4j2Test"); admin.declareQueue(queue); admin.declareBinding(BindingBuilder.bind(queue).to(fanout)); Logger logger = LogManager.getLogger("foo"); logger.info("foo"); logger.info("bar"); template.setReceiveTimeout(10000); Message received = template.receive(queue.getName()); assertThat(received).isNotNull(); assertThat(received.getMessageProperties().getReceivedRoutingKey()).isEqualTo("testAppId.foo.INFO"); Object foo = received.getMessageProperties().getHeader("foo"); assertThat(foo).isNotNull(); assertThat(foo).isInstanceOf(String.class); assertThat(foo).isEqualTo("bar"); assertThat(new String(received.getBody())).startsWith("foo"); received = template.receive(queue.getName()); assertThat(received).isNotNull(); assertThat(received.getMessageProperties().getReceivedRoutingKey()).isEqualTo("testAppId.foo.INFO"); assertThat(new String(received.getBody())).startsWith("bar"); Object threadName = received.getMessageProperties().getHeaders().get("thread"); assertThat(threadName).isNotNull(); assertThat(threadName).isInstanceOf(String.class); assertThat(threadName).isEqualTo(Thread.currentThread().getName()); foo = received.getMessageProperties().getHeaders().get("foo"); assertThat(foo).isNotNull(); assertThat(foo).isInstanceOf(String.class); assertThat(foo).isEqualTo("bar"); ccf.destroy(); }