Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RocketMQ pollable and sql example #3385

Merged
merged 3 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions spring-cloud-alibaba-examples/rocketmq-example/readme-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,17 @@ public class RocketMQSqlConsumeApplication {
}
```

#### 常见问题

- MQClientException: The broker does not support consumer to filter message by SQL92
1. 修改 RocketMQ 服务端配置文件。
在 `conf/2m-2s-async/broker-a.properties` 配置文件末尾添加 `enablePropertyFilter=true`
2. 重启 mqbroker 并指定配置文件。
`mqbroker` 启动时指定配置文件:`conf/2m-2s-async/broker-a.properties`,例如:
```shell
bin/mqbroker -n 127.0.0.1:9876 -c conf/2m-2s-async/broker-a.properties autoCreateTopicEnable=true
```

## 事务消息示例

### 什么是事务消息?
Expand Down
11 changes: 11 additions & 0 deletions spring-cloud-alibaba-examples/rocketmq-example/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,17 @@ public class RocketMQSqlConsumeApplication {
}
```

#### 常见问题

- MQClientException: The broker does not support consumer to filter message by SQL92
1. Modify RocketMQ server configuration file.
In the `conf/2m-2s-async/broker-a.properties` configuration file, add `enablePropertyFilter=true`.
2. Restart mqbroker and specify the configuration file.
Specify the configuration file when `mqbroker` starts: `conf/2m-2s-async/broker-a.properties`, for example:
```shell
bin/mqbroker -n 127.0.0.1:9876 -c conf/2m-2s-async/broker-a.properties autoCreateTopicEnable=true
```

## Transaction example

### What is transactional message?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.binder.PollableMessageSource;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.messaging.Message;
Expand All @@ -48,7 +49,24 @@ public class RocketMQPollableConsumeApplication {
private StreamBridge streamBridge;

public static void main(String[] args) {
SpringApplication.run(RocketMQPollableConsumeApplication.class, args);
ConfigurableApplicationContext context = SpringApplication.run(RocketMQPollableConsumeApplication.class, args);
PollableMessageSource destIn = context.getBean(PollableMessageSource.class);
new Thread(() -> {
while (true) {
try {
if (!destIn.poll((m) -> {
SimpleMsg newPayload = (SimpleMsg) m.getPayload();
System.out.println(newPayload.getMsg());
}, new ParameterizedTypeReference<SimpleMsg>() {
})) {
Thread.sleep(1000);
}
}
catch (Exception e) {
// handle failure
}
}
}).start();
}

@Bean
Expand All @@ -65,22 +83,4 @@ public ApplicationRunner producer() {
};
}

@Bean
public ApplicationRunner pollableRunner(PollableMessageSource destIn) {
return args -> {
while (true) {
try {
if (!destIn.poll((m) -> {
SimpleMsg newPayload = (SimpleMsg) m.getPayload();
System.out.println(newPayload.getMsg());
}, new ParameterizedTypeReference<SimpleMsg>() { })) {
Thread.sleep(1000);
}
}
catch (Exception e) {
// handle failure
}
}
};
}
}