All Projects → QianmiOpen → spring-boot-starter-rocketmq

QianmiOpen / spring-boot-starter-rocketmq

Licence: Apache-2.0 license
Starter for messaging using Apache RocketMQ

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to spring-boot-starter-rocketmq

Rocket-Spring-Integration
🎉🎉RocketMQ与Spring集成,@RocketListener方法注解自动注册🎉🎉
Stars: ✭ 18 (-81.63%)
Mutual labels:  rocketmq
go-developer-roadmap
【Go 学习地图】涵盖业内 Go 面试题和所需要掌握的 Go 核心知识大全
Stars: ✭ 513 (+423.47%)
Mutual labels:  rocketmq
JavaYouth
主要是Java技术栈的文章,涉及到了源码、原理,面试等知识。如AQS,JVM,rpc,计网,os等等,后续可能会写mysql,redis,zk这些
Stars: ✭ 616 (+528.57%)
Mutual labels:  rocketmq
funboost
pip install funboost,python全功能分布式函数调度框架,。支持python所有类型的并发模式和全球一切知名消息队列中间件,python函数加速器,框架包罗万象,一统编程思维,兼容50% python编程业务场景,适用范围广。只需要一行代码即可分布式执行python一切函数。旧名字是function_scheduling_distributed_framework
Stars: ✭ 351 (+258.16%)
Mutual labels:  rocketmq
rocketmq-site
Apache RocketMQ is a cloud native messaging and streaming platform, making it simple to build event-driven applications.
Stars: ✭ 41 (-58.16%)
Mutual labels:  rocketmq
distmq
Distributed Message Queue based on Raft
Stars: ✭ 32 (-67.35%)
Mutual labels:  rocketmq
rocketmq-spring-boot-starter
Rocketmq spring boot starter
Stars: ✭ 17 (-82.65%)
Mutual labels:  rocketmq
short
URL shortening service. 高性能短链接服务。
Stars: ✭ 14 (-85.71%)
Mutual labels:  rocketmq
dubbo-go-pixiu
Based on the proxy gateway service of dubbo-go, it solves the problem that the external protocol calls the internal Dubbo cluster. At present, it supports HTTP and gRPC[developing].
Stars: ✭ 385 (+292.86%)
Mutual labels:  rocketmq
pan
Pan is a high performance mq proxy,support kafka,rabbit-mq,rocketmq,nsq and other mq
Stars: ✭ 27 (-72.45%)
Mutual labels:  rocketmq
JavaFamily
【Java面试+Java学习指南】 一份涵盖大部分Java程序员所需要掌握的核心知识。
Stars: ✭ 517 (+427.55%)
Mutual labels:  rocketmq
wmqx
基于 Rabbitmq 的 Http 异步消息调用服务
Stars: ✭ 40 (-59.18%)
Mutual labels:  rocketmq
docker-case
这个项目主要是为了快速拉起docker服务
Stars: ✭ 31 (-68.37%)
Mutual labels:  rocketmq
mall4cloud
⭐️⭐️⭐️ Springcloud商城 O2O商城 小程序商城 PC商城 H5商城 APP商城 Java商城 分销商城 多用户商城 uniapp商城 微服务商城
Stars: ✭ 3,915 (+3894.9%)
Mutual labels:  rocketmq
taotao-cloud-project
微服务开发脚手架,包括大数据模块、微服务模块、前端模块。基于Spring Cloud Alibaba的微服务架构。提供技术框架的基础能力的封装,减少开发工作,只关注业务,包含了工作以来的工作总结和技术沉淀
Stars: ✭ 76 (-22.45%)
Mutual labels:  rocketmq
rocketmq-client-php
A Php Client for Apache RocketMQ.
Stars: ✭ 80 (-18.37%)
Mutual labels:  rocketmq
robert
基于SpringCloud的企业级微服务多租户系统、多语言的脚手架, 代码组件化、高内聚低耦合,代码简介,注释丰富容易上手,该项目包括用于开发分布式应用程序服务的必要组件,支持多应用程序访问,并使开发人员可以轻松地使用Spring Cloud编程模型来开发分布式应用程序服务。
Stars: ✭ 45 (-54.08%)
Mutual labels:  rocketmq
rocketmq
RocketMQ client for go supportting producer and consumer.
Stars: ✭ 29 (-70.41%)
Mutual labels:  rocketmq
Java-CS-Record
记录准备春招实习过程中,学习与复习的知识(模块化整理,非面试题速成)。注:暂停更新,后续请移步博客
Stars: ✭ 73 (-25.51%)
Mutual labels:  rocketmq
incubator-rocketmq
带中文代码注释 Mirror of Apache RocketMQ 源码解析:http://www.iocoder.cn/categories/RocketMQ/?github
Stars: ✭ 343 (+250%)
Mutual labels:  rocketmq

spring-boot-starter-rocketmq

This project has been contributed to apache,please see:apache/rocketmq-externals/rocketmq-spring-boot-starter

中文

Maven Central Build Status License

Help developers quickly integrate RocketMQ in Spring Boot. Support the Spring Message specification to facilitate developers to quickly switch from other MQ to RocketMQ.

Features:

  • synchronous transmission
  • synchronous ordered transmission
  • asynchronous transmission
  • asynchronous ordered transmission
  • orderly consume
  • concurrently consume(broadcasting/clustering)
  • One-way transmission
  • transaction transmission
  • Pull consume

Quick Start

<!--add dependency in pom.xml-->
<dependency>
    <group>com.qianmi</group>
    <artifactId>spring-boot-starter-rocketmq</artifactId>
    <version>1.1.0-RELEASE</version>
</dependency>

Produce Message

## application.properties
spring.rocketmq.name-server=127.0.0.1:9876
spring.rocketmq.producer.group=my-group

Note:

Maybe you need change 127.0.0.1:9876 with your real NameServer address for RocketMQ

@SpringBootApplication
public class ProducerApplication implements CommandLineRunner{
    @Resource
    private RocketMQTemplate rocketMQTemplate;
    
    public static void main(String[] args){
        SpringApplication.run(ProducerApplication.class, args);
    }
    
    public void run(String... args) throws Exception {
        rocketMQTemplate.convertAndSend("test-topic-1", "Hello, World!");
        rocketMQTemplate.send("test-topic-1", MessageBuilder.withPayload("Hello, World! I'm from spring message").build());
        rocketMQTemplate.convertAndSend("test-topic-2", new OrderPaidEvent("T_001", new BigDecimal("88.00")));
        
//        rocketMQTemplate.destroy(); // notes:  once rocketMQTemplate be destroyed, you can not send any message again with this rocketMQTemplate
    }
    
    @Data
    @AllArgsConstructor
    public class OrderPaidEvent implements Serializable{
        private String orderId;
        
        private BigDecimal paidMoney;
    }
}

More relevant configurations for produce:

spring.rocketmq.producer.retry-times-when-send-async-failed=0
spring.rocketmq.producer.send-msg-timeout=300000
spring.rocketmq.producer.compress-msg-body-over-howmuch=4096
spring.rocketmq.producer.max-message-size=4194304
spring.rocketmq.producer.retry-another-broker-when-not-store-ok=false
spring.rocketmq.producer.retry-times-when-send-failed=2

Consume Message

## application.properties
spring.rocketmq.name-server=127.0.0.1:9876

Note:

Maybe you need change 127.0.0.1:9876 with your real NameServer address for RocketMQ

@SpringBootApplication
public class ConsumerApplication{
    
    public static void main(String[] args){
        SpringApplication.run(ConsumerApplication.class, args);
    }
    
    @Slf4j
    @Service
    @RocketMQMessageListener(topic = "test-topic-1", consumerGroup = "my-consumer_test-topic-1")
    public class MyConsumer1 implements RocketMQListener<String>{
        public void onMessage(String message) {
            log.info("received message: {}", message);
        }
    }
    
    @Slf4j
    @Service
    @RocketMQMessageListener(topic = "test-topic-2", consumerGroup = "my-consumer_test-topic-2")
    public class MyConsumer2 implements RocketMQListener<OrderPaidEvent>{
        public void onMessage(OrderPaidEvent orderPaidEvent) {
            log.info("received orderPaidEvent: {}", orderPaidEvent);
        }
    }
}

More relevant configurations for consume:

see: RocketMQMessageListener

FAQ

  1. How to connected many nameserver on production environment?

    spring.rocketmq.name-server support the configuration of multiple nameserver, separated by ;. For example: 172.19.0.1: 9876; 172.19.0.2: 9876

  2. When was rocketMQTemplate destroyed?

    Developers do not need to manually execute the rocketMQTemplate.destroy () method when using rocketMQTemplate to send a message in the project, and rocketMQTemplate will be destroyed automatically when the spring container is destroyed.

  3. start exception:Caused by: org.apache.rocketmq.client.exception.MQClientException: The consumer group[xxx] has been created before, specify another name please

    RocketMQ in the design do not want a consumer to deal with multiple types of messages at the same time, so the same consumerGroup consumer responsibility should be the same, do not do different things (that is, consumption of multiple topics). Suggested consumerGroup and topic one correspondence.

  4. How is the message content body being serialized and deserialized?

    RocketMQ's message body is stored as byte []. When the business system message content body if it is java.lang.String type, unified in accordance with utf-8 code into byte []; If the business system message content is not java.lang.String Type, then use jackson-databind serialized into the JSON format string, and then unified in accordance with utf-8 code into byte [] .

  5. How do I specify the tags for topic?

    RocketMQ best practice recommended: an application as much as possible with one Topic, the message sub-type with tags to identify, tags can be set by the application free.

    When you use rocketMQTemplate to send a message, set the destination of the message by setting the destination parameter of the send method. The destination format is topicName:tagName, : Precedes the name of the topic, followed by the tags name.

    Note:

    tags looks a complex, but when sending a message , the destination can only specify one topic under a tag, can not specify multiple.

  6. How do I set the message's key when sending a message?

    You can send a message by overloading method like xxxSend(String destination, Message<?> msg, ...), setting headers of msg. for example:

    Message<?> message = MessageBuilder.withPayload(payload).setHeader(MessageConst.PROPERTY_KEYS, msgId).build();
    rocketMQTemplate.send("topic-test", message);

    Similarly, you can also set the message FLAG, WAIT_STORE_MSG_OK and some other user-defined other header information according to the above method.

    Note:

    In the case of converting Spring's Message to RocketMQ's Message, to prevent the header information from conflicting with RocketMQ's system properties, the prefix USERS_ was added in front of all header names. So if you want to get a custom message header when consuming, please pass through the key at the beginning of USERS_ in the header.

  7. When consume message, in addition to get the message payload, but also want to get RocketMQ message of other system attributes, how to do?

    Consumers in the realization of RocketMQListener interface, only need to be generic for the MessageExt can, so in the onMessage method will receive RocketMQ native 'MessageExt` message.

    @Slf4j
    @Service
    @RocketMQMessageListener(topic = "test-topic-1", consumerGroup = "my-consumer_test-topic-1")
    public class MyConsumer2 implements RocketMQListener<MessageExt>{
        public void onMessage(MessageExt messageExt) {
            log.info("received messageExt: {}", messageExt);
        }
    }
  8. How do I specify where consumers start consuming messages?

    The default consume offset please refer: RocketMQ FAQ. To customize the consumer's starting location, simply add a RocketMQPushConsumerLifecycleListener interface implementation to the consumer class. Examples are as follows:

    @Slf4j
    @Service
    @RocketMQMessageListener(topic = "test-topic-1", consumerGroup = "my-consumer_test-topic-1")
    public class MyConsumer1 implements RocketMQListener<String>, RocketMQPushConsumerLifecycleListener {
        @Override
        public void onMessage(String message) {
            log.info("received message: {}", message);
        }
    
        @Override
        public void prepareStart(final DefaultMQPushConsumer consumer) {
            // set consumer consume message from now
            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_TIMESTAMP);
            consumer.setConsumeTimestamp(UtilAll.timeMillisToHumanString3(System.currentTimeMillis()));
        }
    }

    Similarly, any other configuration on DefaultMQPushConsumer can be done in the same way as above.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].