From 0210fee3bc3731e3173f012987bfd9d9f2965958 Mon Sep 17 00:00:00 2001 From: Stanislav Knot Date: Thu, 5 Apr 2018 18:01:41 +0200 Subject: [PATCH] ARTEMIS-1787 Openwire message should not contain internal property --- .../protocol/openwire/amq/AMQSession.java | 4 +++- .../jms/client/NoLocalSubscriberTest.java | 2 -- .../openwire/SimpleOpenWireTest.java | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java index c607ca469b4..281f85ba7b0 100644 --- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java +++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java @@ -376,7 +376,9 @@ public void send(final ProducerInfo producerInfo, final org.apache.activemq.artemis.api.core.Message originalCoreMsg = OpenWireMessageConverter.inbound(messageSend, protocolManagerWireFormat, coreMessageObjectPools); assert clientId.toString().equals(this.connection.getState().getInfo().getClientId()) : "Session cached clientId must be the same of the connection"; - originalCoreMsg.putStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME, clientId); + if (connection.isNoLocal()) { + originalCoreMsg.putStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME, clientId); + } /* ActiveMQ failover transport will attempt to reconnect after connection failure. Any sent messages that did * not receive acks will be resent. (ActiveMQ broker handles this by returning a last sequence id received to diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/NoLocalSubscriberTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/NoLocalSubscriberTest.java index 2df214c925b..a2cf0bf734a 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/NoLocalSubscriberTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/client/NoLocalSubscriberTest.java @@ -171,8 +171,6 @@ public void testNoLocalReconnect() throws Exception { connection.start(); // now drain the subscription - // we should not receive message M3, but we should receive message M4 - // However for some reason Artemis doesn't receive either TextMessage textMessage = (TextMessage) topicSubscriber.receive(1000); assertNotNull(textMessage); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java index 618249bcac9..85f0a9fcb48 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/SimpleOpenWireTest.java @@ -1748,6 +1748,30 @@ public void testXAResourceRolledBackRemoved() throws Exception { assertNull(transaction); } + @Test + public void testMessageDoesNotContainProps() throws Exception { + try (Connection connection = factory.createConnection()) { + + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + Queue queue = session.createQueue(queueName); + System.out.println("Queue:" + queue); + MessageProducer producer = session.createProducer(queue); + MessageConsumer consumer = session.createConsumer(queue); + TextMessage msg = session.createTextMessage("test"); + producer.send(msg); + session.commit(); + + connection.start(); + + TextMessage message = (TextMessage) consumer.receive(5000); + Assert.assertEquals("test", message.getText()); + + Assert.assertNotNull(message); + Assert.assertFalse(message.getPropertyNames().hasMoreElements()); + message.acknowledge(); + } + } + private void checkQueueEmpty(String qName) { PostOffice po = server.getPostOffice(); LocalQueueBinding binding = (LocalQueueBinding) po.getBinding(SimpleString.toSimpleString(qName));