Skip to content

Commit

Permalink
release 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
pufang committed Jan 30, 2018
1 parent 75ebcec commit 20c92e1
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 423 deletions.
86 changes: 54 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,113 @@
<p><a href="http://search.maven.org/#search%7Cga%7C1%7Ccom.maihaoche"><img src="https://maven-badges.herokuapp.com/maven-central/com.maihaoche/spring-boot-starter-rocketmq/badge.svg" alt="Maven Central" style="max-width:100%;"></a><a href="https://github.com/maihaoche/rocketmq-spring-boot-starter/releases"><img src="https://camo.githubusercontent.com/795f06dcbec8d5adcfadc1eb7a8ac9c7d5007fce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656c656173652d646f776e6c6f61642d6f72616e67652e737667" alt="GitHub release" data-canonical-src="https://img.shields.io/badge/release-download-orange.svg" style="max-width:100%;"></a>


### 项目介绍

### 1. 添加maven依赖:
[Rocketmq](https://github.com/apache/rocketmq) 是由阿里巴巴团队开发并捐赠给apache团队的优秀消息中间件,承受过历年双十一大促的考验。

你可以通过本项目轻松的集成Rocketmq到你的SpringBoot项目中。
本项目主要包含以下特性

* [x] 同步发送消息
* [x] 异步发送消息
* [x] 广播发送消息
* [x] 有序发送和消费消息
* [x] 发送延时消息
* [x] 消息tag和key支持
* [x] 自动序列化和反序列化消息体
* [x] 消息的消息方追溯
* [ ] ...


### 简单入门实例


##### 1. 添加maven依赖:

```
<dependency>
<groupId>com.maihaoche</groupId>
<artifactId>spring-boot-starter-rocketmq</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
</dependency>
```

### 2. 添加配置:
##### 2. 添加配置:

```
rocketmq:
name-server-address: 172.21.10.111:9876
# 可选, 如果无需发送消息则忽略该配置
producer-group: local_pufang_producer
# 发送超时配置毫秒数, 可选, 默认3000
send-msg-timeout: 5000
# 追溯消息具体消费情况的开关
#trace-enabled: true
spring:
rocketmq:
name-server-address: 172.21.10.111:9876
# 可选, 如果无需发送消息则忽略该配置
producer-group: local_pufang_producer
# 发送超时配置毫秒数, 可选, 默认3000
send-msg-timeout: 5000
# 追溯消息具体消费情况的开关,默认打开
#trace-enabled: false
# 追溯消息具体消费情况的开关,默认打开
#vip-channel-enabled: false
```
### 3. 入口添加注解开启自动装配
##### 3. 程序入口添加注解开启自动装配

在springboot应用主入口添加`@EnableMQConfiguration`注解开启自动装配:

```
@SpringBootApplication
@EnableMQConfiguration
class CamaroDemoApplication {
class DemoApplication {
}
```

### 4. 定义消息体
##### 4. 构建消息体

可以通过`@MQKey`注解将消息POJO中的对应字段设置为消息key,通过`prefix`定义key的前缀:
通过我们提供的`Builder`类创建消息对象,详见[wiki](https://github.com/maihaoche/rocketmq-spring-boot-starter/wiki/构建消息体)

```
data class DemoMessage(
@MQKey(prefix = "sku_")
val skuId:Long,
val skuType:String)

```
MessageBuilder.of(new MSG_POJO()).topic("some-msg-topic").build();
```


### 5. 创建发送方
##### 5. 创建发送方

详见[wiki](https://github.com/maihaoche/rocketmq-spring-boot-starter/wiki/%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5-Provider)


```
@MQProducer
class DemoProducer : AbstractMQProducer() {
public class DemoProducer extends AbstractMQProducer{
}
```

### 6. 创建消费方
##### 6. 创建消费方

详见[wiki](https://github.com/maihaoche/rocketmq-spring-boot-starter/wiki/%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5-Consumer)

```
@MQConsumer(consumerGroup = "local_pufang_test_consumer", topic = "suclogger")
class DemoConsumer : AbstractMQPushConsumer<DemoMessage>() {
override fun process(message: DemoMessage?, extMap: MutableMap<String, Any>?): Boolean {
@MQConsumer(topic = "suclogger-test-cluster", consumerGroup = "local_sucloger_dev")
public class DemoConsumer extends AbstractMQPushConsumer {
@Override
public boolean process(Object message, Map extMap) {
// extMap 中包含messageExt中的属性和message.properties中的属性
println("message id : ${extMap!![MessageExtConst.PROPERTY_EXT_MSG_ID]}")
return true
System.out.println(message);
return true;
}
}
```

### 7. 发送消息:
##### 7. 发送消息:

```
// 注入发送者
@Autowired
lateinit var demoProducer:DemoProducer
private DemoProducer demoProducer;
...
// 发送
demoProducer.syncSend("suclogger", DemoMessage(1, "plain_message"))
demoProducer.syncSend(msg)
```

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<groupId>com.maihaoche</groupId>
<artifactId>spring-boot-starter-rocketmq</artifactId>
<version>0.0.6-SNAPSHOT</version>
<version>0.0.6</version>

<scm>
<url>https://github.com/maihaoche/rocketmq-spring-boot-starter</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@
@Documented
@Component
public @interface MQProducer {
String topic() default "";
String tag() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.util.Assert;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.util.Assert;

/**
* Description:RocketMQ消费抽象基类
* Created by Jay Chang on 2017/9/14
Expand Down
Loading

0 comments on commit 20c92e1

Please sign in to comment.