use of org.apache.rocketmq.spring.starter.core.RocketMQTemplate in project rocketmq-externals by apache.
the class RocketMQAutoConfigurationTests method rocketMQTemplate.
@Test
public void rocketMQTemplate() {
load("spring.rocketmq.nameServer=127.0.0.1:9876", "spring.rocketmq.producer.group=my_group", "spring.rocketmq.producer.send-msg-timeout=30000", "spring.rocketmq.producer.retry-times-when-send-async-failed=1", "spring.rocketmq.producer.compress-msg-body-over-howmuch=1024", "spring.rocketmq.producer.max-message-size=10240", "spring.rocketmq.producer.retry-another-broker-when-not-store-ok=true", "spring.rocketmq.producer.retry-times-when-send-failed=1");
assertThat(this.context.containsBean("rocketMQMessageObjectMapper")).isTrue();
assertThat(this.context.containsBean("mqProducer")).isTrue();
assertThat(this.context.containsBean("rocketMQTemplate")).isTrue();
assertThat(this.context.getBeansOfType(DefaultRocketMQListenerContainer.class)).isEmpty();
RocketMQTemplate rocketMQTemplate = this.context.getBean(RocketMQTemplate.class);
ObjectMapper objectMapper = this.context.getBean("rocketMQMessageObjectMapper", ObjectMapper.class);
assertThat(rocketMQTemplate.getObjectMapper()).isEqualTo(objectMapper);
DefaultMQProducer defaultMQProducer = rocketMQTemplate.getProducer();
assertThat(defaultMQProducer.getNamesrvAddr()).isEqualTo("127.0.0.1:9876");
assertThat(defaultMQProducer.getProducerGroup()).isEqualTo("my_group");
assertThat(defaultMQProducer.getSendMsgTimeout()).isEqualTo(30000);
assertThat(defaultMQProducer.getRetryTimesWhenSendAsyncFailed()).isEqualTo(1);
assertThat(defaultMQProducer.getCompressMsgBodyOverHowmuch()).isEqualTo(1024);
assertThat(defaultMQProducer.getMaxMessageSize()).isEqualTo(10240);
assertThat(defaultMQProducer.isRetryAnotherBrokerWhenNotStoreOK()).isTrue();
assertThat(defaultMQProducer.getRetryTimesWhenSendFailed()).isEqualTo(1);
}
use of org.apache.rocketmq.spring.starter.core.RocketMQTemplate in project rocketmq-externals by apache.
the class RocketMQAutoConfiguration method rocketMQTemplate.
@Bean(destroyMethod = "destroy")
@ConditionalOnBean(DefaultMQProducer.class)
@ConditionalOnMissingBean(name = "rocketMQTemplate")
public RocketMQTemplate rocketMQTemplate(DefaultMQProducer mqProducer, @Autowired(required = false) @Qualifier("rocketMQMessageObjectMapper") ObjectMapper objectMapper) {
RocketMQTemplate rocketMQTemplate = new RocketMQTemplate();
rocketMQTemplate.setProducer(mqProducer);
if (Objects.nonNull(objectMapper)) {
rocketMQTemplate.setObjectMapper(objectMapper);
}
return rocketMQTemplate;
}
Aggregations