下面列出了怎么用org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void overrideActiveMqQueue() throws Exception {
this.context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.jms.cache.enabled", "false");
environment().setProperty("spring.zipkin.activemq.queue", "zipkin2");
environment().setProperty("spring.zipkin.activemq.message-max-bytes", "50");
environment().setProperty("spring.zipkin.sender.type", "activemq");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ActiveMQAutoConfiguration.class, ZipkinAutoConfiguration.class,
TraceAutoConfiguration.class);
this.context.refresh();
then(this.context.getBean(Sender.class)).isInstanceOf(ActiveMQSender.class);
this.context.close();
}
@Test
public void eventRegistryWithJms() {
contextRunner
.withConfiguration(AutoConfigurations.of(
ActiveMQAutoConfiguration.class,
JmsAutoConfiguration.class
))
.run(context -> {
assertThat(context)
.hasSingleBean(JmsChannelModelProcessor.class)
.hasBean("jmsChannelDefinitionProcessor");
EventRegistryEngine eventRegistryEngine = context.getBean(EventRegistryEngine.class);
assertThat(eventRegistryEngine).as("Event registry engine").isNotNull();
EventRegistryEngineConfiguration eventRegistryEngineConfiguration = eventRegistryEngine.getEventRegistryEngineConfiguration();
IterableAssert<ChannelModelProcessor> channelModelProcessorAssert = assertThat(
eventRegistryEngineConfiguration.getChannelModelProcessors());
channelModelProcessorAssert
.hasSize(5);
channelModelProcessorAssert
.element(0)
.isEqualTo(context.getBean("jmsChannelDefinitionProcessor", ChannelModelProcessor.class));
channelModelProcessorAssert
.element(1)
.isInstanceOf(DelegateExpressionInboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(2)
.isInstanceOf(DelegateExpressionOutboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(3)
.isInstanceOf(InboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(4)
.isInstanceOf(OutboundChannelModelProcessor.class);
});
}
@Test
public void eventRegistryWithJmsRabbitAndKafka() {
contextRunner
.withConfiguration(AutoConfigurations.of(
ActiveMQAutoConfiguration.class,
JmsAutoConfiguration.class,
RabbitAutoConfiguration.class,
KafkaAutoConfiguration.class
))
.run(context -> {
assertThat(context)
.hasSingleBean(JmsChannelModelProcessor.class)
.hasBean("jmsChannelDefinitionProcessor")
.hasSingleBean(RabbitChannelDefinitionProcessor.class)
.hasBean("rabbitChannelDefinitionProcessor")
.hasSingleBean(KafkaChannelDefinitionProcessor.class)
.hasBean("kafkaChannelDefinitionProcessor");
EventRegistryEngine eventRegistryEngine = context.getBean(EventRegistryEngine.class);
assertThat(eventRegistryEngine).as("Event registry engine").isNotNull();
EventRegistryEngineConfiguration eventRegistryEngineConfiguration = eventRegistryEngine.getEventRegistryEngineConfiguration();
IterableAssert<ChannelModelProcessor> channelModelProcessorAssert = assertThat(
eventRegistryEngineConfiguration.getChannelModelProcessors());
channelModelProcessorAssert
.hasSize(7)
.contains(
context.getBean("jmsChannelDefinitionProcessor", JmsChannelModelProcessor.class),
context.getBean("rabbitChannelDefinitionProcessor", RabbitChannelDefinitionProcessor.class),
context.getBean("kafkaChannelDefinitionProcessor", KafkaChannelDefinitionProcessor.class)
);
channelModelProcessorAssert
.element(3)
.isInstanceOf(DelegateExpressionInboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(4)
.isInstanceOf(DelegateExpressionOutboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(5)
.isInstanceOf(InboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(6)
.isInstanceOf(OutboundChannelModelProcessor.class);
});
}
@Test
public void eventRegistryWithCustomDefinitionProcessors() {
contextRunner
.withConfiguration(AutoConfigurations.of(
ActiveMQAutoConfiguration.class,
JmsAutoConfiguration.class,
RabbitAutoConfiguration.class,
KafkaAutoConfiguration.class
))
.withUserConfiguration(CustomChannelDefinitionProcessorsConfiguration.class)
.run(context -> {
assertThat(context)
.doesNotHaveBean(JmsChannelModelProcessor.class)
.hasBean("jmsChannelDefinitionProcessor")
.doesNotHaveBean(RabbitChannelDefinitionProcessor.class)
.hasBean("rabbitChannelDefinitionProcessor")
.doesNotHaveBean(KafkaChannelDefinitionProcessor.class)
.hasBean("kafkaChannelDefinitionProcessor")
.hasBean("customChannelDefinitionProcessor");
EventRegistryEngine eventRegistryEngine = context.getBean(EventRegistryEngine.class);
assertThat(eventRegistryEngine).as("Event registry engine").isNotNull();
EventRegistryEngineConfiguration eventRegistryEngineConfiguration = eventRegistryEngine.getEventRegistryEngineConfiguration();
IterableAssert<ChannelModelProcessor> channelModelProcessorAssert = assertThat(
eventRegistryEngineConfiguration.getChannelModelProcessors());
channelModelProcessorAssert
.hasSize(8);
channelModelProcessorAssert
.element(0)
.isEqualTo(context.getBean("customChannelDefinitionProcessor", ChannelModelProcessor.class));
channelModelProcessorAssert
.element(1)
.isEqualTo(context.getBean("rabbitChannelDefinitionProcessor", ChannelModelProcessor.class));
channelModelProcessorAssert
.element(2)
.isEqualTo(context.getBean("jmsChannelDefinitionProcessor", ChannelModelProcessor.class));
channelModelProcessorAssert
.element(3)
.isEqualTo(context.getBean("kafkaChannelDefinitionProcessor", ChannelModelProcessor.class));
channelModelProcessorAssert
.element(4)
.isInstanceOf(DelegateExpressionInboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(5)
.isInstanceOf(DelegateExpressionOutboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(6)
.isInstanceOf(InboundChannelModelProcessor.class);
channelModelProcessorAssert
.element(7)
.isInstanceOf(OutboundChannelModelProcessor.class);
});
}