Coder Social home page Coder Social logo

rocketmq-spring-boot-starter's Introduction

rocketmq-spring-boot-starter

AliYun RocketMQ Spring Book Edition

中文

Thanks for the help from JetBrains software

The project follows the Apache2.0 License
The license is free. You can download the code, modify it as needed, and use it in your own projects

Important: all projects published by the author on GitHub are non-profit.
Since the author registered GitHub, so far, he hasn't made a penny.
Anyone who charges for the author's project is cheating you.
If you are cheated, I hope you can get the help of a lawyer. Good luck.

IMPORTANT: The author is currently living in a miserable situation with no income and is running out of money.
The project still follows the Apache2.0 License
If the author has no money to eat, the author cannot update the project for everyone for free in a place without Internet and life.
The author is now accepting donations, thank you for your support.
The time to start accepting donations is when this text is currently updated.
Donate

IMPORTANT: This project is now out of maintenance, as the author needs to pay to maintain the commercial version while maintaining the project.
We spent money maintaining a commercial version today, but couldn't use the product.
We have decided to suspend the maintenance or update of all Ali products.
Maintainers of open source projects don't pay entrepreneurs to work for free because they disable your account.

IMPORTANT: Ali decided to sanction me, today I received a text message, he forced me to pay for maintaining Ali products.
I paid what I needed to pay yesterday, which is to maintain the Ali product, and then canceled the paid product, but I was sanctioned anyway, and now I have to pay more.
Good luck to everyone, don't be sanctioned by Ali.

Support function:

  • Three modes of sending ordinary messages: synchronous, asynchronous and one-way
  • Subscribe to Message Cluster, Broadcast
  • Send and receive sequential messages
  • Transaction messages
  • Delay message
  • receive and receive timing messages

Timing message and delay message:

Delay message and timing message: In the official case, delayed news is much the same as regular news, essentially ordinary news.

If delay message and timing message are needed, it is recommended to use timing task (timing task scheduling platform)

To achieve the purpose of delay or timing.

Transaction message:

In the framework, the operations on transaction messages are simpler and simpler. You can complete the transaction messages by annotations only.

Whether transactional messages, distributed transactional solutions or cross-platform language solutions, the core problem of transactional solutions is to ensure that messages can be sent and consumers can consume them.

Reliability Guarantee

1.Add @TransactionMessage annotation, kernel guarantee, local transaction error, do not send message, correct execution, send message, that is, default submission.

2.Reliability assurance is adopted by default, and default submission is checked back. The reason comes from the previous factor, which guarantees that local transactions do not go wrong.

Quick Start

<!--Adding dependencies to pom. XML-->
        <dependency>
            <artifactId>rocketmq-spring-boot-starter</artifactId>
            <groupId>com.github.thierrysquirrel</groupId>
            <version>2.3.1.4-RELEASE</version>
        </dependency>

configuration file

## application.properties
thierrysquirrel.access-key= #The Access Key you created in the AliYun Account Management Console for authentication
thierrysquirrel.secret-key= #The SecretKey you created in the AliYun Account Management Console for authentication
thierrysquirrel.name-srv-addr= #Set up TCP protocol access point and get it from console

Start RocketMQ

@SpringBootApplication
@EnableRocketMQ
public class DemoApplication{
    public static void main(String[] args){
        SpringApplication.run(DemoApplication.class, args);
    }
   
}

Three Ways to Send Common Messages

@RestController
@RocketMessage(groupID = "GID_common")
public class Common {

    @GetMapping("/commonA")
    @CommonMessage(topic = "commonA", tag = "commonA",messageSendType = MessageSendType.SEND)
    public String sendCommonMsg() {
        return "commonA";
    }
    @GetMapping("/commonB")
    @CommonMessage(topic = "commonB", tag = "commonB",messageSendType = MessageSendType.SEND_ASYNC)
    public String sendAsyncMsg() {
        return "commonB";
    }
    @GetMapping("/commonC")
    @CommonMessage(topic = "commonC", tag = "commonC",messageSendType = MessageSendType.SEND_ONE_WAY)
    public String sendOneWayMessage() {
        return "commonC";
    }
}

Send sequential messages

@RestController
@RocketMessage(groupID = "GID_order")
public class Order {
    @GetMapping("/order")
    @OrderMessage(topic = "order",tag = "order")
    public String order(@RequestParam @ShardingKey String shardingKey) {
        return "order";
    }
}

Send Transaction Messages

@RestController
@RocketMessage(groupID = "GID_transaction")
public class Transaction {
    @GetMapping("/transaction")
    @TransactionMessage(topic = "transaction",tag = "transaction")
    public String transaction() {
        return "transaction";
    }
}

Delay message or timing message

@RestController
@RocketMessage(groupID = "GID_delayed")
public class Delayed {
    //startDeliverTime is the time stamp, which cannot be less than the current time
    @GetMapping("/delayed")
    @CommonMessage(topic = "delayed", tag = "delayed")
    public String delayed(@StartDeliverTime @RequestParam("startDeliverTime") long startDeliverTime) {
        return "delayed";
    }
}

Subscribe to regular, transactional, delayed, timed messages

Monitor messages using messageModel to control cluster or broadcast consumption patterns

@RocketListener(groupID = "GID_message",messageModel = PropertyValueConst.CLUSTERING)
public class Delayed {
    @MessageListener(topic = "message",tag = "message")    
    public void delayed(String message) {
        System.out.println("message");
    }
}

Subscription order message

@RocketListener(groupID = "GID_message",messageModel = PropertyValueConst.BROADCASTING)
public class Delayed {
    @MessageListener(topic = "message",tag = "message", orderConsumer = true)
    public void delayed(String message) {
            System.out.println("message");
    }
}

Batch Mode

@RocketListener(groupID = "GID_message",batchConsumer = true)
public class Delayed {
	@MessageListener(topic = "message",tag = "message", orderConsumer = true)
	public void delayed(String message) {
		System.out.println("message");
	}
}

Developer-defined global module

Custom Implementation of Message Sending Results

    @Component
    public class MySendCallback implements SendCallback {
        @Override
        public void onSuccess(SendResult sendResult) {
            System.out.println("Successful sending of message");
        }
        @Override
        public void onException(OnExceptionContext context) {
            System.out.println("Failed to send message");
        }
    }

Customize whether local transactions are executed

@Component
public class MyTransactionExecuter implements LocalTransactionExecuter {
    @Override
    public TransactionStatus execute(Message msg, Object arg) {
        System.out.println("Executing local affairs");
        return TransactionStatus.CommitTransaction;
    }
}

Custom review of local transactions

@Component
public class MyTransactionChecker implements LocalTransactionChecker {
    @Override
    public TransactionStatus check(Message msg) {
        System.out.println("Review of local transactions");
        return TransactionStatus.CommitTransaction;
    }
}

Custom RocketSerializer

@Component
public class JacksonSerializer implements RocketSerializer {
	private static ObjectMapper objectMapper = new ObjectMapper();
    @Override
    public byte[] serialize(Object obj) {
        //omit
    }
    @Override
    public Object deserialize(byte[] bytes, Class<?> clazz) {
        //omit
    }
}

Developer-defined Local Modules

@CommonMessage callback Specify the class

@TransactionMessage checker And executer Specify the class

Russian flag

rocketmq-spring-boot-starter's People

Contributors

thierrysquirrel avatar

Stargazers

 avatar  avatar

Watchers

 avatar

rocketmq-spring-boot-starter's Issues

分区顺序消息

分区顺序消息应该是没支持吧,目前shardingkey在OrderMessage注解中只是一个值,应该达不到分区顺序消息的需求

多环境可以支持吗?

比如我的mq的topic,group每个环境都不一样,如果在注解中的代码里写死很麻烦吧

TransactionMessage能否支持自定义LocalTransactionChecker?

PutProducerStrategy中指定使用DefaultLocalTransactionChecker,这个checker应该是需要自己根据各自的业务去自行扩展的吧。 另外TransactionMessage注解中transactionStatus属性也有点不理解,不应该是根据checker里的查询结果返回不同的status吗?

默认的DefaultMessageListener实现BUG

<dependency>
            <artifactId>rocketmq-spring-boot-starter</artifactId>
            <groupId>com.github.thierrysquirrel</groupId>
            <version>2.0.6-RELEASE</version>
        </dependency>

如果用户只是想接收到字符串
图片
那么如果消息中的如果带有“:” 则解析会直接抛出解析异常
可以在实现的时候判断下如果接收者要的就是String类型 那么可以不用做json转换

异步多线程处理,处理失败抛出的RocketException异常,可以执行Action.ReconsumeLater?

@MessageListener(topic = "message",tag = "message")
public void delayed(String message) {
// 异步多线程处理,处理失败抛出的RocketException异常,可以执行Action.ReconsumeLater?
asynTask.do();
}

我看源码里面是抛出异常就会执行ACK
public Action consume(Message message, ConsumeContext context) {
log.info(">>>>listener message:{}>>>>", message);
try {
super.getMethodFactoryExecution().methodExecution(message.getBody());
} catch (RocketException e) {
super.printErrorLog();
return Action.ReconsumeLater;
}
return Action.CommitMessage;
}

注册 Consumer 的问题

在这一段代码中 会根据 MessageListener 的注解来注册 consumer
image
但是当出现多个 MessageListener 的时候会在 阿里云控制台注册多个 consumer 那这个消费岂不是针对方法级别的了
` @MessageListener(topic = "sdongpos-common",tag = "order")
public void consumerOrderMsg(String message) {
System.out.println("consumerMsg : "+message);
}

@MessageListener(topic = "sdongpos-common",tag = "commonA")
public void consumerCommonMsg(String message) {
    System.out.println("consumercommonMsg : "+message);
}

@MessageListener(topic = "sdongpos-common",tag = "commonB")
public void consumerCommonBMsg(String message) {
    System.out.println("consumercommonMsg : "+message);
}

`这个是阿里云控制台的图片
image

No route info for this topic

想法非常好,但是报No route info for this topic

我加了:@EnableRocketMQ
有没有需要注意的点

引入后 启动项目时 报错

image

Error:(4, 45) java: 无法访问com.github.thierrysquirrel.annotation.EnableRocketMQ
错误的类文件: /D:/repo/com/github/thierrysquirrel/rocketmq-spring-boot-autoconfigure/2.3.0.6-RELEASE/rocketmq-spring-boot-autoconfigure-2.3.0.6-RELEASE.jar!/com/github/thierrysquirrel/annotation/EnableRocketMQ.class
类文件具有错误的版本 55.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.