Skip to content

Commit

Permalink
DevicePublishMsg rename topic to topicName
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-landiak committed Nov 18, 2024
1 parent 2a74573 commit fbfa6ee
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.netty.handler.codec.mqtt.MqttProperties.UserProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.thingsboard.mqtt.broker.common.data.BrokerConstants;
import org.thingsboard.mqtt.broker.common.data.ClientInfo;
import org.thingsboard.mqtt.broker.common.data.ClientSessionInfo;
import org.thingsboard.mqtt.broker.common.data.ClientType;
Expand All @@ -29,7 +30,6 @@
import org.thingsboard.mqtt.broker.common.data.SessionInfo;
import org.thingsboard.mqtt.broker.common.data.subscription.SubscriptionOptions;
import org.thingsboard.mqtt.broker.common.data.subscription.TopicSubscription;
import org.thingsboard.mqtt.broker.common.data.BrokerConstants;
import org.thingsboard.mqtt.broker.gen.queue.QueueProtos;
import org.thingsboard.mqtt.broker.queue.TbQueueMsgHeaders;
import org.thingsboard.mqtt.broker.service.mqtt.PublishMsg;
Expand Down Expand Up @@ -80,7 +80,7 @@ public static QueueProtos.PublishMsgProto convertToPublishMsgProto(DevicePublish
UserProperties userProperties = MqttPropertiesUtil.getUserProperties(devicePublishMsg.getProperties());
QueueProtos.PublishMsgProto.Builder builder = QueueProtos.PublishMsgProto.newBuilder()
.setPacketId(devicePublishMsg.getPacketId())
.setTopicName(devicePublishMsg.getTopic())
.setTopicName(devicePublishMsg.getTopicName())
.setQos(devicePublishMsg.getQos())
.setPayload(ByteString.copyFrom(devicePublishMsg.getPayload()))
.addAllUserProperties(toUserPropertyProtos(userProperties))
Expand Down Expand Up @@ -169,7 +169,7 @@ public static DevicePublishMsg protoToDevicePublishMsg(String clientId, QueuePro
MqttPropertiesUtil.addMsgExpiryIntervalToProps(mqttProperties, headers);
return DevicePublishMsg.builder()
.clientId(clientId)
.topic(publishMsgProto.getTopicName())
.topicName(publishMsgProto.getTopicName())
.qos(publishMsgProto.getQos())
.payload(publishMsgProto.getPayload().toByteArray())
.properties(mqttProperties)
Expand All @@ -187,7 +187,7 @@ public static QueueProtos.DevicePublishMsgProto toDevicePublishMsgProto(DevicePu
.setPacketId(devicePublishMsg.getPacketId())
.setPayload(ByteString.copyFrom(devicePublishMsg.getPayload()))
.setQos(devicePublishMsg.getQos())
.setTopicName(devicePublishMsg.getTopic())
.setTopicName(devicePublishMsg.getTopicName())
.setClientId(devicePublishMsg.getClientId())
.setPacketType(devicePublishMsg.getPacketType().toString())
.addAllUserProperties(toUserPropertyProtos(userProperties))
Expand All @@ -212,7 +212,7 @@ public static DevicePublishMsg protoToDevicePublishMsg(QueueProtos.DevicePublish
.packetId(devicePublishMsgProto.getPacketId())
.payload(devicePublishMsgProto.getPayload().toByteArray())
.qos(devicePublishMsgProto.getQos())
.topic(devicePublishMsgProto.getTopicName())
.topicName(devicePublishMsgProto.getTopicName())
.clientId(devicePublishMsgProto.getClientId())
.packetType(PersistedPacketType.valueOf(devicePublishMsgProto.getPacketType()))
.properties(properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public MqttPublishMessage createPubMsg(PublishMsg pubMsg) {
@Override
public MqttPublishMessage createPubMsg(DevicePublishMsg pubMsg, boolean isDup) {
return getMqttPublishMessage(isDup, pubMsg.getQos(), pubMsg.isRetained(),
pubMsg.getTopic(), pubMsg.getPacketId(), pubMsg.getPayload(), pubMsg.getProperties());
pubMsg.getTopicName(), pubMsg.getPacketId(), pubMsg.getPayload(), pubMsg.getProperties());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public PublishMsg createPublishMsgUsingTopicAlias(PublishMsg publishMsg, int min

public DevicePublishMsg createPublishMsgUsingTopicAlias(DevicePublishMsg publishMsg, int minTopicNameLengthForAliasReplacement) {
if (enabled) {
boolean setEmptyTopic = updateTopicAlias(publishMsg.getTopic(), publishMsg.getProperties(), minTopicNameLengthForAliasReplacement);
boolean setEmptyTopic = updateTopicAlias(publishMsg.getTopicName(), publishMsg.getProperties(), minTopicNameLengthForAliasReplacement);
if (setEmptyTopic) {
return publishMsg.toBuilder().topic(BrokerConstants.EMPTY_STR).build();
return publishMsg.toBuilder().topicName(BrokerConstants.EMPTY_STR).build();
}
}
return publishMsg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.thingsboard.mqtt.broker.common.data.BrokerConstants;
import org.thingsboard.mqtt.broker.common.data.ClientInfo;
import org.thingsboard.mqtt.broker.common.data.ClientSessionInfo;
import org.thingsboard.mqtt.broker.common.data.ClientType;
Expand All @@ -31,7 +32,6 @@
import org.thingsboard.mqtt.broker.common.data.SessionInfo;
import org.thingsboard.mqtt.broker.common.data.subscription.SubscriptionOptions;
import org.thingsboard.mqtt.broker.common.data.subscription.TopicSubscription;
import org.thingsboard.mqtt.broker.common.data.BrokerConstants;
import org.thingsboard.mqtt.broker.gen.queue.QueueProtos;
import org.thingsboard.mqtt.broker.service.mqtt.PublishMsg;
import org.thingsboard.mqtt.broker.service.mqtt.retain.RetainedMsg;
Expand Down Expand Up @@ -324,7 +324,7 @@ public void givenDevicePubMsgProto_whenExecuteProtoToDevicePublishMsg_thenGetExp
.build();

DevicePublishMsg devicePublishMsg = ProtoConverter.protoToDevicePublishMsg(proto);
assertEquals("topic", devicePublishMsg.getTopic());
assertEquals("topic", devicePublishMsg.getTopicName());
assertEquals(1, devicePublishMsg.getQos());
assertEquals(PersistedPacketType.PUBLISH, devicePublishMsg.getPacketType());
assertNull(devicePublishMsg.getProperties().getProperty(BrokerConstants.PAYLOAD_FORMAT_INDICATOR_PROP_ID));
Expand All @@ -344,7 +344,7 @@ public void givenDevicePubMsg_whenExecuteToDevicePublishMsgProto_thenGetExpected
.payload("p".getBytes(StandardCharsets.UTF_8))
.packetType(PersistedPacketType.PUBREL)
.clientId("cli")
.topic("topic")
.topicName("topic")
.packetId(124)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void givenDevicePubMsgWithSmallTopic_whenCreateDevicePublishMsgUsingTopic

DevicePublishMsg publishMsg = DevicePublishMsg
.builder()
.topic("topic/1")
.topicName("topic/1")
.properties(new MqttProperties())
.build();

Expand Down Expand Up @@ -173,7 +173,7 @@ public void givenDevicePubMsgWithTopicAndMaxAllowedAliases_whenCreateDevicePubli

DevicePublishMsg publishMsg = DevicePublishMsg
.builder()
.topic("topic/qwerty")
.topicName("topic/qwerty")
.properties(new MqttProperties())
.build();

Expand Down Expand Up @@ -206,13 +206,13 @@ public void givenDevicePubMsgWithTopic_whenCreateDevicePublishMsgUsingTopicAlias

DevicePublishMsg publishMsg = DevicePublishMsg
.builder()
.topic("topic/qwerty")
.topicName("topic/qwerty")
.properties(new MqttProperties())
.build();

DevicePublishMsg publishMsgUsingTopicAlias = topicAliasCtx.createPublishMsgUsingTopicAlias(publishMsg, minTopicNameLengthForAliasReplacement);

Assert.assertEquals("topic/qwerty", publishMsgUsingTopicAlias.getTopic());
Assert.assertEquals("topic/qwerty", publishMsgUsingTopicAlias.getTopicName());
int topicAlias = (int) publishMsgUsingTopicAlias.getProperties().getProperty(BrokerConstants.TOPIC_ALIAS_PROP_ID).value();
Assert.assertEquals(2, topicAlias);
Assert.assertEquals(2, topicAliasCtx.getServerMappings().size());
Expand Down Expand Up @@ -242,13 +242,13 @@ public void givenDevicePubMsgWithTopicAndExisingMapping_whenCreateDevicePublishM

DevicePublishMsg publishMsg = DevicePublishMsg
.builder()
.topic("topic123456")
.topicName("topic123456")
.properties(new MqttProperties())
.build();

DevicePublishMsg publishMsgUsingTopicAlias = topicAliasCtx.createPublishMsgUsingTopicAlias(publishMsg, minTopicNameLengthForAliasReplacement);

Assert.assertEquals(BrokerConstants.EMPTY_STR, publishMsgUsingTopicAlias.getTopic());
Assert.assertEquals(BrokerConstants.EMPTY_STR, publishMsgUsingTopicAlias.getTopicName());
int topicAlias = (int) publishMsgUsingTopicAlias.getProperties().getProperty(BrokerConstants.TOPIC_ALIAS_PROP_ID).value();
Assert.assertEquals(1, topicAlias);
Assert.assertEquals(1, topicAliasCtx.getServerMappings().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class DevicePublishMsg {

private String clientId;
private String topic;
private String topicName;
private Long time;
private Integer qos;
private Integer packetId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static DevicePublishMsg fromCsvRecord(CSVRecord record, int defaultTtl) t
// non-null fields
String clientId = record.get("client_id");
devicePublishMsg.setClientId(clientId);
devicePublishMsg.setTopic(record.get("topic"));
devicePublishMsg.setTopicName(record.get("topic"));
devicePublishMsg.setTime(Long.parseLong(record.get("time")));

devicePublishMsg.setPacketId(Integer.parseInt(record.get("packet_id")));
Expand Down

0 comments on commit fbfa6ee

Please sign in to comment.