Skip to content

Commit 3840681

Browse files
committed
[broker-25] update logging, mqtt mock client
1 parent c2266bf commit 3840681

29 files changed

+218
-125
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ allprojects {
3232

3333
ext {
3434
annotationVersion = "17.0.0"
35-
rlibVersion = "9.8.0"
35+
rlibVersion = "9.9.0"
3636
lombokVersion = '1.18.4'
3737
springbootVersion = '2.2.0.RELEASE'
3838
springVersion = '5.1.6.RELEASE'
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.ss.mqtt.broker;
22

33
import com.ss.mqtt.broker.config.MqttBrokerConfig;
4-
import com.ss.rlib.common.concurrent.util.ConcurrentUtils;
54
import lombok.RequiredArgsConstructor;
5+
import lombok.extern.log4j.Log4j2;
66
import org.jetbrains.annotations.NotNull;
77
import org.springframework.boot.SpringApplication;
88
import org.springframework.context.annotation.Configuration;
99
import org.springframework.context.annotation.Import;
1010

11-
@Import({
12-
MqttBrokerConfig.class
13-
})
11+
@Log4j2
1412
@Configuration
1513
@RequiredArgsConstructor
14+
@Import(MqttBrokerConfig.class)
1615
public class MqttBrokerApplication {
1716

1817
public static void main(@NotNull String[] args) {
19-
ConcurrentUtils.wait(SpringApplication.run(MqttBrokerApplication.class, args));
18+
SpringApplication.run(MqttBrokerApplication.class, args);
2019
}
2120
}

src/main/java/com/ss/mqtt/broker/config/MqttBrokerConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private interface ChannelFactory extends
6262
return new InMemoryClientIdRegistry(
6363
env.getProperty(
6464
"client.id.available.chars",
65-
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-"
65+
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
6666
),
6767
env.getProperty("client.id.max.length", int.class, 36)
6868
);

src/main/java/com/ss/mqtt/broker/model/impl/DefaultMqttSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public boolean hasInPending(int packetId) {
150150
@Override
151151
public void resendPendingPackets(@NotNull MqttClient mqttClient) {
152152
pendingOutPublishes.forEachInReadLock(mqttClient, (client, pending) -> {
153-
log.info("Re-try to send publish {}", pending.publish);
153+
log.debug("Re-try to send publish {}", pending.publish);
154154
pending.handler.resend(client, pending.publish, pending.packetId);
155155
});
156156
}

src/main/java/com/ss/mqtt/broker/model/topic/AbstractTopic.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ss.mqtt.broker.model.topic;
22

3+
import com.ss.mqtt.broker.util.DebugUtils;
34
import com.ss.rlib.common.util.ArrayUtils;
45
import com.ss.rlib.common.util.StringUtils;
56
import lombok.EqualsAndHashCode;
@@ -10,6 +11,10 @@
1011
@EqualsAndHashCode(of = "rawTopic")
1112
public abstract class AbstractTopic {
1213

14+
static {
15+
DebugUtils.registerIncludedFields("rawTopic");
16+
}
17+
1318
static final String DELIMITER = "/";
1419
static final String MULTI_LEVEL_WILDCARD = "#";
1520
static final String SINGLE_LEVEL_WILDCARD = "+";

src/main/java/com/ss/mqtt/broker/network/client/AbstractMqttClient.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.ss.mqtt.broker.factory.packet.out.MqttPacketOutFactory;
1010
import com.ss.mqtt.broker.network.packet.in.MqttReadablePacket;
1111
import com.ss.mqtt.broker.network.packet.out.MqttWritablePacket;
12+
import com.ss.mqtt.broker.util.DebugUtils;
1213
import com.ss.rlib.common.util.StringUtils;
1314
import lombok.EqualsAndHashCode;
1415
import lombok.Getter;
@@ -24,9 +25,12 @@
2425

2526
@Getter
2627
@Log4j2
27-
@ToString(of = "clientId")
2828
public abstract class AbstractMqttClient implements UnsafeMqttClient {
2929

30+
static {
31+
DebugUtils.registerIncludedFields("clientId");
32+
}
33+
3034
protected final @NotNull MqttConnection connection;
3135
protected final MqttClientReleaseHandler releaseHandler;
3236
protected final AtomicBoolean released;
@@ -58,7 +62,7 @@ public AbstractMqttClient(@NotNull MqttConnection connection, @NotNull MqttClien
5862

5963
@Override
6064
public void handle(@NotNull MqttReadablePacket packet) {
61-
log.info("Handle received packet: {} : {}", packet.getName(), packet);
65+
log.debug("Client [{}] received packet: {} : {}", clientId, packet.getName(), packet);
6266

6367
var packetHandler = connection.getPacketHandlers()[packet.getPacketType()];
6468

@@ -90,11 +94,13 @@ public void configure(
9094

9195
@Override
9296
public void send(@NotNull MqttWritablePacket packet) {
97+
log.debug("Send to client [{}] packet: {} : {}", clientId, packet.getName(), packet);
9398
connection.send(packet);
9499
}
95100

96101
@Override
97102
public @NotNull CompletableFuture<Boolean> sendWithFeedback(@NotNull MqttWritablePacket packet) {
103+
log.debug("Send to client [{}] packet: {} : {}", clientId, packet.getName(), packet);
98104
return connection.sendWithFeedback(packet);
99105
}
100106

@@ -122,4 +128,9 @@ public void reject(@NotNull ConnectAckReasonCode reasonCode) {
122128
return Mono.empty();
123129
}
124130
}
131+
132+
@Override
133+
public @NotNull String toString() {
134+
return DebugUtils.toJsonString(this);
135+
}
125136
}

src/main/java/com/ss/mqtt/broker/network/client/DeviceMqttClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
import com.ss.mqtt.broker.network.MqttConnection;
44
import com.ss.mqtt.broker.handler.client.MqttClientReleaseHandler;
5+
import com.ss.mqtt.broker.util.DebugUtils;
56
import org.jetbrains.annotations.NotNull;
67

78
public class DeviceMqttClient extends AbstractMqttClient {
89

10+
static {
11+
DebugUtils.registerIncludedFields("clientId");
12+
}
13+
914
public DeviceMqttClient(@NotNull MqttConnection connection, @NotNull MqttClientReleaseHandler releaseHandler) {
1015
super(connection, releaseHandler);
1116
}

src/main/java/com/ss/mqtt/broker/network/packet/in/ConnectInPacket.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class ConnectInPacket extends MqttReadablePacket {
2727

2828
private static final byte PACKET_TYPE = (byte) PacketType.CONNECT.ordinal();
2929

30+
static {
31+
DebugUtils.registerIncludedFields("clientId", "keepAlive", "cleanStart");
32+
}
33+
3034
private static final Set<PacketProperty> AVAILABLE_PROPERTIES = EnumSet.of(
3135
/*
3236
If the Session Expiry Interval is absent the value 0 is used. If it is set to 0,
@@ -398,9 +402,4 @@ protected void applyProperty(@NotNull PacketProperty property, long value) {
398402
unexpectedProperty(property);
399403
}
400404
}
401-
402-
@Override
403-
public @NotNull String toString() {
404-
return DebugUtils.toJsonString(this);
405-
}
406405
}

src/main/java/com/ss/mqtt/broker/network/packet/in/DisconnectInPacket.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public class DisconnectInPacket extends MqttReadablePacket {
2323

2424
public static final byte PACKET_TYPE = (byte) PacketType.DISCONNECT.ordinal();
2525

26+
static {
27+
DebugUtils.registerIncludedFields("reasonCode");
28+
}
29+
2630
private static final Set<PacketProperty> AVAILABLE_PROPERTIES = EnumSet.of(
2731
/*
2832
If the Session Expiry Interval is absent, the Session Expiry Interval in the CONNECT packet is used.
@@ -126,9 +130,4 @@ protected void applyProperty(@NotNull PacketProperty property, @NotNull String v
126130
unexpectedProperty(property);
127131
}
128132
}
129-
130-
@Override
131-
public @NotNull String toString() {
132-
return DebugUtils.toJsonString(this);
133-
}
134133
}

src/main/java/com/ss/mqtt/broker/network/packet/in/MqttReadablePacket.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.ss.mqtt.broker.model.PacketProperty;
99
import com.ss.mqtt.broker.model.data.type.StringPair;
1010
import com.ss.mqtt.broker.network.MqttConnection;
11+
import com.ss.mqtt.broker.util.DebugUtils;
1112
import com.ss.mqtt.broker.util.MqttDataUtils;
1213
import com.ss.rlib.common.util.ArrayUtils;
1314
import com.ss.rlib.common.util.array.Array;
@@ -232,4 +233,9 @@ protected long readUnsignedInt(@NotNull ByteBuffer buffer) {
232233
protected void unexpectedProperty(@NotNull PacketProperty property) {
233234
throw new IllegalArgumentException("Unsupported property: " + property);
234235
}
236+
237+
@Override
238+
public @NotNull String toString() {
239+
return DebugUtils.toJsonString(this);
240+
}
235241
}

0 commit comments

Comments
 (0)