[
https://issues.apache.org/jira/browse/ARTEMIS-4370?focusedWorklogId=872555&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-872555
]
ASF GitHub Bot logged work on ARTEMIS-4370:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 24/Jul/23 14:37
Start Date: 24/Jul/23 14:37
Worklog Time Spent: 10m
Work Description: jbertram commented on code in PR #4563:
URL: https://github.com/apache/activemq-artemis/pull/4563#discussion_r1272357028
##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt5/spec/controlpackets/PublishTests.java:
##########
@@ -1020,6 +1020,74 @@ public void messageArrived(String topic, MqttMessage
message) throws Exception {
consumer.disconnect();
}
+ /*
+ * From section 3.3.2.3.4 of the MQTT 5 specification:
+ *
+ * A sender can modify the Topic Alias mapping by sending another PUBLISH
in the same Network Connection with the
+ * same Topic Alias value and a different non-zero length Topic Name.
+ */
+ @Test(timeout = DEFAULT_TIMEOUT)
+ public void testModifiedTopicAlias() throws Exception {
+ final String TOPIC_1 = this.getTopicName() + "1";
+ final String TOPIC_2 = this.getTopicName() + "2";
+
+ MqttClient consumer1 = createPahoClient("consumer1");
+ CountDownLatch latch1 = new CountDownLatch(2);
+ consumer1.setCallback(new DefaultMqttCallback() {
+ @Override
+ public void messageArrived(String topic, MqttMessage message) throws
Exception {
+ String payload = new String(message.getPayload());
+ if (payload.equals("first") || payload.equals("second")) {
+ latch1.countDown();
+ }
+ }
+ });
+ consumer1.connect();
+ consumer1.subscribe(TOPIC_1, 1);
+
+ MqttClient consumer2 = createPahoClient("consumer2");
+ CountDownLatch latch2 = new CountDownLatch(2);
+ consumer2.setCallback(new DefaultMqttCallback() {
+ @Override
+ public void messageArrived(String topic, MqttMessage message) throws
Exception {
+ String payload = new String(message.getPayload());
+ if (payload.equals("third") || payload.equals("fourth")) {
+ latch2.countDown();
+ }
+ }
+ });
+ consumer2.connect();
+ consumer2.subscribe(TOPIC_2, 1);
+
+ MqttClient producer = createPahoClient("producer");
+ producer.connect();
+
+ MqttProperties properties = new MqttProperties();
+ properties.setTopicAlias(1);
+ MqttMessage m = new MqttMessage();
+ m.setProperties(properties);
+ m.setQos(1);
+ m.setRetained(false);
+ m.setPayload("first".getBytes(StandardCharsets.UTF_8));
+ producer.publish(TOPIC_1, m);
+ m.setPayload("second".getBytes(StandardCharsets.UTF_8));
+ producer.publish("", m);
Review Comment:
I forgot that I had modified my local version of the Paho MQTT 5 client to
disable topic validation. I fixed the test.
Issue Time Tracking
-------------------
Worklog Id: (was: 872555)
Time Spent: 0.5h (was: 20m)
> Publishing message with existing topic alias and different topic causes
> message to be sent to incorrect topic
> -------------------------------------------------------------------------------------------------------------
>
> Key: ARTEMIS-4370
> URL: https://issues.apache.org/jira/browse/ARTEMIS-4370
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Components: MQTT
> Affects Versions: 2.29.0
> Reporter: Adam Zyzak
> Assignee: Justin Bertram
> Priority: Major
> Fix For: 2.31.0
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> h3. Description
> When sending MQTT 5.0 publish message with topic alias number that has
> existing mapping for given connection and new topic, Artemis broker will
> incorrectly route message to topic from alias mapping instead of topic from
> publish message. This is incorrect behavior because broker should route
> message to topic from publish message and update alias mapping with new
> topic.
> Section 3.3.2.3.4 Topic Alias in MQTT 5.0 specification states the following:
> {code:java}
> A sender can modify the Topic Alias mapping by sending another PUBLISH in the
> same Network Connection with the same Topic Alias value and a different
> non-zero length Topic Name. {code}
>
> h3. Steps to reproduce
> # Create 2 MQTT subscribers: first on topic1 and second on topic2
> # Create 1 MQTT publisher
> # From publisher send publish message on topic1 with MQTT property
> TOPIC_ALIAS set to 1
> # From publisher send publish message on topic2 with MQTT property
> TOPIC_ALIAS set to 1
> h3. Current result
> First message is correctly routed to topic1, but second message is
> incorrectly routed to topic1 instead of topic2
> Method
> org.apache.activemq.artemis.core.protocol.mqtt.MQTTPublishManager#sendToQueue
> adds mapping only if alias does not exist
> h3. Expected result
> Topic field in MQTT publish should have priority over TOPIC_ALIAS property.
> Topic alias stored under existing alias number should be updated.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)