Search in sources :

Example 1 with RocketMQTemplate

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);
}
Also used : RocketMQTemplate(org.apache.rocketmq.spring.starter.core.RocketMQTemplate) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with RocketMQTemplate

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;
}
Also used : RocketMQTemplate(org.apache.rocketmq.spring.starter.core.RocketMQTemplate) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) InitializingBean(org.springframework.beans.factory.InitializingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

RocketMQTemplate (org.apache.rocketmq.spring.starter.core.RocketMQTemplate)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)1 Test (org.junit.Test)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1