Skip to content

Commit

Permalink
Merge pull request #156 from DongyuanPan/develop_fix_unit_test
Browse files Browse the repository at this point in the history
fix unit test
  • Loading branch information
pingww authored Oct 20, 2022
2 parents e754f3d + af1cdf9 commit af04be9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@
package org.apache.rocketmq.mqtt.cs.protocol.mqtt.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.mqtt.MqttFixedHeader;
import io.netty.handler.codec.mqtt.MqttMessage;
import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader;
import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttQoS;
import org.apache.rocketmq.mqtt.common.hook.HookResult;
import org.apache.rocketmq.mqtt.cs.channel.ChannelInfo;
import org.apache.rocketmq.mqtt.cs.protocol.mqtt.MqttPacketHandler;
import org.apache.rocketmq.mqtt.cs.protocol.mqtt.facotry.MqttMessageFactory;
import org.apache.rocketmq.mqtt.cs.session.infly.RetryDriver;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MqttPubRecHandler implements MqttPacketHandler<MqttMessage> {

private final MqttFixedHeader pubRelMqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL, false,
MqttQoS.AT_LEAST_ONCE, false, 0);
@Resource
private RetryDriver retryDriver;

Expand All @@ -47,6 +50,7 @@ public void doHandler(ChannelHandlerContext ctx, MqttMessage mqttMessage, HookRe
retryDriver.unMountPublish(variableHeader.messageId(), channelId);
retryDriver.mountPubRel(variableHeader.messageId(), channelId);

ctx.channel().writeAndFlush(MqttMessageFactory.buildPubRelMessage(variableHeader));
MqttMessage pubRelMqttMessage = new MqttMessage(pubRelMqttFixedHeader, variableHeader);
ctx.channel().writeAndFlush(pubRelMqttMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

public class MqttConsumer {
public static void main(String[] args) throws MqttException, NoSuchAlgorithmException, InvalidKeyException {
String brokerUrl = System.getenv("brokerUrl");
String brokerUrl = "tcp://11.164.2.4:1883";
String firstTopic = "dongyuan-f1";
MemoryPersistence memoryPersistence = new MemoryPersistence();
String firstTopic = System.getenv("firstTopic");
String recvClientId = "recv01";
MqttConnectOptions mqttConnectOptions = buildMqttConnectOptions(recvClientId);
MqttClient mqttClient = new MqttClient(brokerUrl, recvClientId, memoryPersistence);
Expand Down Expand Up @@ -89,8 +89,8 @@ private static MqttConnectOptions buildMqttConnectOptions(String clientId) throw
connOpts.setKeepAliveInterval(60);
connOpts.setAutomaticReconnect(true);
connOpts.setMaxInflight(10000);
connOpts.setUserName(System.getenv("username"));
connOpts.setPassword(HmacSHA1Util.macSignature(clientId, System.getenv("secretKey")).toCharArray());
connOpts.setUserName("passwd");
connOpts.setPassword(HmacSHA1Util.macSignature(clientId, "passwd").toCharArray());
return connOpts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
public class MqttProducer {
public static void main(String[] args) throws InterruptedException, MqttException, NoSuchAlgorithmException, InvalidKeyException {
MemoryPersistence memoryPersistence = new MemoryPersistence();
String brokerUrl = System.getenv("brokerUrl");
String firstTopic = System.getenv("firstTopic");
String brokerUrl = "tcp://11.164.2.4:1883";
String firstTopic = "dongyuan-f1";
String sendClientId = "send01";
String recvClientId = "recv01";
MqttConnectOptions mqttConnectOptions = buildMqttConnectOptions(sendClientId);
Expand Down Expand Up @@ -100,8 +100,8 @@ private static MqttConnectOptions buildMqttConnectOptions(String clientId) throw
connOpts.setKeepAliveInterval(60);
connOpts.setAutomaticReconnect(true);
connOpts.setMaxInflight(10000);
connOpts.setUserName(System.getenv("username"));
connOpts.setPassword(HmacSHA1Util.macSignature(clientId, System.getenv("secretKey")).toCharArray());
connOpts.setUserName("passwd");
connOpts.setPassword(HmacSHA1Util.macSignature(clientId, "passwd").toCharArray());
return connOpts;
}

Expand Down

0 comments on commit af04be9

Please sign in to comment.