百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

spring-boot-starter-rocketmq

> 后端框架
开源

使用 Apache RocketMQ 的消息传输启动程序

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

使用 Apache RocketMQ 的消息传输启动程序

spring-boot-starter-rocketmq

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

中文 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

xml

    com.qianmi
    spring-boot-starter-rocketmq
    1.1.0-RELEASE

Produce Message

properties
## 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

…

More relevant configurations for produce:

properties
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

properties
## 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

…

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:

    java
    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.

    java
    @Slf4j
    @Service
    @RocketMQMessageListener(topic = "test-topic-1", consumerGroup = "my-consumer_test-topic-1")
    public class MyConsumer2 implements RocketMQListener{
        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:

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javarocketmqspring-boot

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架