New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARTEMIS-607 Added interceptor support for MQTT protocol. #617
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.activemq.artemis.core.protocol.mqtt; | ||
|
||
import io.netty.handler.codec.mqtt.MqttMessage; | ||
import org.apache.activemq.artemis.api.core.BaseInterceptor; | ||
|
||
public interface MQTTInterceptor extends BaseInterceptor<MqttMessage> { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.activemq.artemis.spi.core.protocol; | ||
|
||
import org.apache.activemq.artemis.api.core.BaseInterceptor; | ||
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; | ||
|
||
import java.util.List; | ||
|
||
public abstract class AbstractProtocolManager<P, I extends BaseInterceptor<P>, C extends RemotingConnection> | ||
implements ProtocolManager<I> { | ||
|
||
protected void invokeInterceptors(final List<I> interceptors, | ||
final P message, | ||
final C connection) { | ||
if (interceptors != null && !interceptors.isEmpty()) { | ||
for (I interceptor : interceptors) { | ||
try { | ||
if (!interceptor.intercept(message, connection)) { | ||
break; | ||
} | ||
} | ||
catch (Exception e) { | ||
ActiveMQServerLogger.LOGGER.error(e); | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,7 +246,9 @@ public void testSendAndReceiveAtLeastOnce() throws Exception { | |
} | ||
|
||
@Test(timeout = 60 * 1000) | ||
public void testSendAndReceiveExactlyOnce() throws Exception { | ||
public void testSendAndReceiveExactlyOnceWithInterceptors() throws Exception { | ||
MQTTIncomingInterceptor.clear(); | ||
MQTTOutoingInterceptor.clear(); | ||
final MQTTClientProvider publisher = getMQTTClientProvider(); | ||
initializeConnection(publisher); | ||
|
||
|
@@ -263,6 +265,8 @@ public void testSendAndReceiveExactlyOnce() throws Exception { | |
} | ||
subscriber.disconnect(); | ||
publisher.disconnect(); | ||
assertEquals(NUM_MESSAGES, MQTTIncomingInterceptor.getMessageCount()); | ||
assertEquals(NUM_MESSAGES, MQTTOutoingInterceptor.getMessageCount()); | ||
} | ||
|
||
@Test(timeout = 60 * 1000) | ||
|
@@ -380,7 +384,8 @@ public void testMQTTPathPatterns() throws Exception { | |
Message msg = connection.receive(5, TimeUnit.SECONDS); | ||
do { | ||
assertNotNull("RETAINED null " + wildcard, msg); | ||
assertTrue("RETAINED prefix " + wildcard, new String(msg.getPayload()).startsWith(RETAINED)); | ||
String msgPayload = new String(msg.getPayload()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One worrisome thing. I think there's some interdependence in these tests. I originally added my interceptor checks in a new test method. When I did that, this test started failing. It was receiving the messages created previously. I suspect the server isn't getting cleaned up 100% correctly, or maybe not at all. |
||
assertTrue("RETAINED prefix " + wildcard + " msg " + msgPayload, msgPayload.startsWith(RETAINED)); | ||
assertTrue("RETAINED matching " + wildcard + " " + msg.getTopic(), pattern.matcher(msg.getTopic()).matches()); | ||
msg.ack(); | ||
msg = connection.receive(5000, TimeUnit.MILLISECONDS); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny thing. I'd myself change that to
sounds more like standard Java-speak to me that way.