DongyuanPan commented on code in PR #314:
URL: https://github.com/apache/rocketmq-mqtt/pull/314#discussion_r2149291111
##########
mqtt-ds/src/main/java/org/apache/rocketmq/mqtt/ds/upstream/processor/PublishProcessor.java:
##########
@@ -62,13 +69,57 @@ public class PublishProcessor implements UpstreamProcessor,
WillMsgSender {
@Override
public CompletableFuture<HookResult> process(MqttMessageUpContext context,
MqttMessage mqttMessage) {
- CompletableFuture<StoreResult> r = put(context, mqttMessage);
- return r.thenCompose(storeResult ->
HookResult.newHookResult(HookResult.SUCCESS, null,
- JSON.toJSONBytes(storeResult)));
+ CompletableFuture<StoreResult> storeFuture = put(context, mqttMessage);
+
+ return storeFuture
+ .thenCompose(storeResult -> {
+ return HookResult.newHookResult(HookResult.SUCCESS, null,
JSON.toJSONBytes(storeResult));
+ })
+ .exceptionally(throwable -> {
+ Throwable cause = throwable.getCause() != null ?
throwable.getCause() : throwable;
+
+ if (cause instanceof MqttRetainException) {
+ logger.warn("A defined business rejection occurred: {}",
cause.getMessage());
+ return new HookResult(HookResult.FAIL, cause.getMessage(),
null);
+ }
+ logger.error("An unexpected error will be propagated up.",
cause);
+ throw new CompletionException(cause);
+ });
}
public CompletableFuture<StoreResult> put(MqttMessageUpContext context,
MqttMessage mqttMessage) {
MqttPublishMessage mqttPublishMessage = (MqttPublishMessage)
mqttMessage;
+
+ if (mqttPublishMessage.fixedHeader().isRetain()) {
Review Comment:
This code can be simplified and less intrusive. For example
```
if (mqttPublishMessage.fixedHeader().isRetain() &&
!serviceConf.isEnableMetaModule()) {
logger.error("Client [{}] on topic [{}] tried to publish a Retain Message,
but the meta module is disabled. Rejecting request.",
context.getClientId(),
mqttPublishMessage.variableHeader().topicName());
MqttRetainException exception = new
MqttRetainException("Retain Message feature is disabled.");
CompletableFuture<StoreResult> failedFuture = new
CompletableFuture<>();
failedFuture.completeExceptionally(exception);
return failedFuture;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]