From c2431a6dd18faa738c58e7f4e6e3aaf4f64fcf53 Mon Sep 17 00:00:00 2001 From: Jiwei Guo Date: Thu, 24 Oct 2024 20:51:35 +0800 Subject: [PATCH] Seperate proxy and broker a single module (#1510) --- .ci/Dockerfile | 2 +- .github/workflows/pr_test.yml | 4 +- README.md | 2 +- {mqtt-impl => mqtt-broker}/pom.xml | 7 + .../src/assemble/bin.xml | 0 .../mqtt/broker/MQTTProtocolHandler.java | 0 .../mqtt/broker/MQTTServerConfiguration.java | 0 .../handlers/mqtt/broker/MQTTService.java | 7 +- .../channel/MQTTBrokerInboundHandler.java | 60 ++ .../channel/MQTTChannelInitializer.java | 2 +- .../mqtt/broker/channel/MQTTServerCnx.java | 0 .../mqtt/broker/channel}/package-info.java | 2 +- .../mqtt/broker/codec/MqttWebSocketCodec.java | 0 .../mqtt/broker/codec/package-info.java | 14 + .../MQTTNamespaceBundleOwnershipListener.java | 0 .../broker/impl/MQTTSubscriptionManager.java | 0 .../impl/MQTTTopicOwnershipListener.java | 0 .../broker/impl/PulsarMessageConverter.java | 1 + .../broker/impl/consumer/MQTTConsumer.java | 2 +- .../impl/consumer/MessagePublishContext.java | 0 .../impl/consumer/OutstandingPacket.java | 0 .../consumer/OutstandingPacketContainer.java | 0 .../OutstandingPacketContainerImpl.java | 0 .../broker/impl/consumer/package-info.java | 0 .../mqtt/broker/impl/package-info.java | 0 .../broker/metric/MQTTMetricsCollector.java | 0 .../broker/metric/MQTTMetricsProvider.java | 0 .../mqtt/broker/metric/package-info.java | 14 + .../mqtt/broker/mqtt5/WillMessageHandler.java | 0 .../mqtt/broker/mqtt5/package-info.java | 0 .../handlers/mqtt/broker/package-info.java | 0 .../MQTTBrokerProtocolMethodProcessor.java | 2 +- .../mqtt/broker/processor/package-info.java | 14 + .../broker/qos/AbstractQosPublishHandler.java | 2 +- .../mqtt/broker/qos/Qos0PublishHandler.java | 0 .../mqtt/broker/qos/Qos1PublishHandler.java | 0 .../mqtt/broker/qos/Qos2PublishHandler.java | 0 .../mqtt/broker/qos/QosPublishHandler.java | 0 .../mqtt/broker/qos/QosPublishHandlers.java | 0 .../broker/qos/QosPublishHandlersImpl.java | 0 .../mqtt/broker/qos/package-info.java | 0 .../broker/rest/MQTTAdditionalServlet.java | 0 .../mqtt/broker/rest/MQTTServiceServlet.java | 0 .../mqtt/broker/rest/package-info.java | 14 + .../pulsar/handlers/mqtt/package-info.java | 0 .../META-INF/services/additional_servlet.yml | 0 .../services/pulsar-protocol-handler.yml | 0 .../mqtt/MQTTSubscriptionManagerTest.java | 0 .../mqtt/broker/MQTTMetricsCollectorTest.java | 0 .../mqtt/broker/MQTTMetricsProviderTest.java | 0 .../mqtt/broker/MessageAckTrackerTest.java | 2 +- .../mqtt/untils/ConfigurationUtilsTest.java | 0 .../mqtt/untils/MqttMessageUtilsTest.java | 0 .../mqtt/untils/PacketIdGeneratorTest.java | 2 +- .../mqtt/untils/PulsarTopicUtilsTest.java | 0 .../mqtt/untils/TopicFilterImplTest.java | 0 .../src/test/resources/mqtt-test.conf | 0 .../src/test/resources/mtls/cel-test.txt | 0 .../src/test/resources/mtls/client-cert.pem | 0 .../src/test/resources/mtls/client.cer | 0 mqtt-common/pom.xml | 27 + .../pulsar/handlers/mqtt/MopVersion.java | 0 ...AbstractCommonProtocolMethodProcessor.java | 1 - .../handlers/mqtt/common/Connection.java | 5 +- .../handlers/mqtt/common/Constants.java | 0 .../mqtt/common/MQTTCommonConfiguration.java | 0 .../mqtt/common/MQTTCommonInboundHandler.java | 19 +- .../mqtt/common/MQTTConnectionManager.java | 0 .../mqtt/common}/ProtocolMethodProcessor.java | 2 +- .../handlers/mqtt/common/TopicFilter.java | 0 .../handlers/mqtt/common/TopicFilterImpl.java | 0 .../common/adapter/CombineAdapterHandler.java | 0 .../mqtt/common/adapter/CombineHandler.java | 0 .../common/adapter/MqttAdapterDecoder.java | 0 .../common/adapter/MqttAdapterEncoder.java | 0 .../common/adapter/MqttAdapterMessage.java | 0 .../mqtt/common/adapter/package-info.java | 0 .../MQTTAuthenticationService.java | 20 +- .../common/authentication/package-info.java | 0 .../common/event/AutoSubscribeHandler.java | 0 .../mqtt/common/event/DisableEventCenter.java | 0 .../mqtt/common/event/PulsarEventCenter.java | 0 .../common/event/PulsarEventCenterImpl.java | 0 .../common/event/PulsarEventListener.java | 0 .../event/PulsarTopicChangeListener.java | 0 .../mqtt/common/event/package-info.java | 0 .../common/exception/MQTTAuthException.java | 0 .../MQTTDuplicatedSubscriptionException.java | 0 .../MQTTNoMatchingSubscriberException.java | 0 .../MQTTNoSubscriptionExistedException.java | 0 .../common/exception/MQTTServerException.java | 0 .../MQTTTopicAliasExceedsLimitException.java | 0 .../MQTTTopicAliasNotFoundException.java | 0 .../MQTTTopicNotExistedException.java | 0 .../mqtt/common/exception/package-info.java | 0 .../InvalidReceiveMaximumException.java | 0 ...InvalidSessionExpireIntervalException.java | 0 .../exception/restrictions/package-info.java | 0 .../common/messages/MqttPropertyUtils.java | 0 .../mqtt/common/messages/ack/MqttAck.java | 0 .../common/messages/ack/MqttConnectAck.java | 0 .../messages/ack/MqttDisconnectAck.java | 0 .../mqtt/common/messages/ack/MqttPubAck.java | 0 .../mqtt/common/messages/ack/MqttSubAck.java | 0 .../common/messages/ack/MqttUnsubAck.java | 0 .../common/messages/ack/package-info.java | 0 .../common/messages/codes/MqttReasonCode.java | 0 .../codes/mqtt3/Mqtt3ConnReasonCode.java | 0 .../codes/mqtt3/Mqtt3SubReasonCode.java | 0 .../messages/codes/mqtt3/package-info.java | 0 .../codes/mqtt5/Mqtt5ConnReasonCode.java | 0 .../codes/mqtt5/Mqtt5DisConnReasonCode.java | 0 .../codes/mqtt5/Mqtt5PubReasonCode.java | 0 .../codes/mqtt5/Mqtt5SubReasonCode.java | 0 .../codes/mqtt5/Mqtt5UnsubReasonCode.java | 0 .../messages/codes/mqtt5/package-info.java | 0 .../common/messages/codes/package-info.java | 0 .../mqtt/common/messages/package-info.java | 0 .../messages/properties/PulsarProperties.java | 0 .../messages/properties/package-info.java | 0 .../mqtt/common/mqtt5}/PacketIdGenerator.java | 2 +- .../common/mqtt5/RetainedMessageHandler.java | 0 .../mqtt/common/mqtt5}/TopicAliasManager.java | 2 +- .../mqtt5}/TopicSubscriptionManager.java | 2 +- .../mqtt/common/mqtt5/package-info.java | 0 .../restrictions/ClientRestrictions.java | 0 .../restrictions/ServerRestrictions.java | 0 .../mqtt5/restrictions/package-info.java | 0 .../handlers/mqtt/common/package-info.java | 0 .../mqtt/common/psk/PSKClientKeyManager.java | 0 .../mqtt/common/psk/PSKConfiguration.java | 23 +- .../mqtt/common/psk/PSKSecretKey.java | 0 .../mqtt/common/psk/PSKSecretKeyStore.java | 0 .../mqtt/common/psk/PSKServerKeyManager.java | 0 .../handlers/mqtt/common/psk/PSKUtils.java | 0 .../mqtt/common/psk/package-info.java | 0 .../mqtt/common/systemtopic/ActionType.java | 0 .../mqtt/common/systemtopic/ConnectEvent.java | 0 .../DisabledSystemEventService.java | 0 .../common/systemtopic/EventListener.java | 0 .../mqtt/common/systemtopic/EventType.java | 0 .../systemtopic/LastWillMessageEvent.java | 0 .../MQTTEventSystemTopicClient.java | 0 .../mqtt/common/systemtopic/MqttEvent.java | 0 .../common/systemtopic/MqttEventUtils.java | 0 .../mqtt/common/systemtopic/PSKEvent.java | 0 .../systemtopic/RetainedMessageEvent.java | 0 .../mqtt/common/systemtopic/SourceEvent.java | 0 .../systemtopic/SystemEventService.java | 0 .../SystemTopicBasedSystemEventService.java | 0 .../mqtt/common/systemtopic/package-info.java | 0 .../mqtt/common/utils/ConfigurationUtils.java | 13 + .../mqtt/common/utils/EventParserUtils.java | 0 .../mqtt/common/utils/FutureUtils.java | 0 .../mqtt/common/utils/MessageBuilder.java | 0 .../mqtt/common/utils/MqttMessageUtils.java | 0 .../handlers/mqtt/common/utils/MqttUtils.java | 0 .../mqtt/common/utils/NettyUtils.java | 0 .../handlers/mqtt/common/utils/Paths.java | 0 .../mqtt/common/utils/PulsarTopicUtils.java | 0 .../mqtt/common/utils/RetainedMessage.java | 0 .../mqtt/common/utils/WillMessage.java | 0 .../mqtt/common/utils/package-info.java | 0 .../pulsar/handlers/mqtt/package-info.java | 14 + .../broker/channel/MQTTInboundHandler.java | 38 - .../mqtt/broker/channel/package-info.java | 18 - .../mqtt/broker/processor/package-info.java | 18 - mqtt-proxy/pom.xml | 58 ++ .../oidc/broker/common/OIDCConstants.java | 0 .../oidc/broker/common/OIDCPoolResources.java | 0 .../oidc/broker/common/package-info.java | 0 .../oidc/broker/common/pojo/Pool.java | 0 .../oidc/broker/common/utils/Paths.java | 0 .../pulsar/handlers/mqtt/package-info.java | 14 + .../mqtt/proxy/MQTTProxyConfiguration.java | 7 + .../mqtt/proxy/MQTTProxyProtocolHandler.java | 137 +++ .../handlers/mqtt/proxy/MQTTProxyService.java | 66 +- .../authentication/mtls/AuthRequest.java | 2 +- .../mtls/AuthenticationProviderMTls.java | 2 +- .../mtls/ExpressionCompiler.java | 2 +- .../authentication/mtls/package-info.java | 14 + .../proxy/authentication/package-info.java | 14 + .../mqtt/proxy/channel}/AdapterChannel.java | 3 +- .../mqtt/proxy/channel}/MQTTProxyAdapter.java | 8 +- .../channel}/MQTTProxyChannelInitializer.java | 5 +- .../channel}/MQTTProxyInboundHandler.java | 4 +- .../mqtt/proxy/channel}/package-info.java | 2 +- .../mqtt/proxy/handler}/LookupHandler.java | 2 +- .../handler}/PulsarServiceLookupHandler.java | 3 +- .../mqtt/proxy/handler}/package-info.java | 2 +- .../mqtt/proxy/impl}/MQTTProxyException.java | 2 +- .../MQTTProxyProtocolMethodProcessor.java | 9 +- .../mqtt/proxy/impl}/MessageAckTracker.java | 2 +- .../mqtt/proxy/impl}/package-info.java | 2 +- .../handlers/mqtt/proxy/package-info.java | 0 .../services/pulsar-protocol-handler.yml | 17 + .../mtls/AuthenticationProviderMTlsTest.java | 2 +- .../proxy/impl/MessageAckTrackerTest.java | 33 + mqtt-proxy/src/test/resources/mqtt-test.conf | 985 ++++++++++++++++++ .../src/test/resources/mtls/cel-test.txt | 1 + .../src/test/resources/mtls/client-cert.pem | 72 ++ mqtt-proxy/src/test/resources/mtls/client.cer | 18 + pom.xml | 4 +- scripts/build.sh | 2 +- tests/pom.xml | 2 +- .../mqtt/broker/AdapterChannelTest.java | 4 +- .../mqtt/broker/MqttProxyAdapterTest.java | 2 +- 207 files changed, 1683 insertions(+), 176 deletions(-) rename {mqtt-impl => mqtt-broker}/pom.xml (88%) rename {mqtt-impl => mqtt-broker}/src/assemble/bin.xml (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTProtocolHandler.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTServerConfiguration.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTService.java (95%) create mode 100644 mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTBrokerInboundHandler.java rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTChannelInitializer.java (98%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTServerCnx.java (100%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls => mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel}/package-info.java (88%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/MqttWebSocketCodec.java (100%) create mode 100644 mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/package-info.java rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTNamespaceBundleOwnershipListener.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTSubscriptionManager.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTTopicOwnershipListener.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/PulsarMessageConverter.java (99%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MQTTConsumer.java (99%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MessagePublishContext.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacket.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainer.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainerImpl.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/package-info.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/package-info.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsCollector.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsProvider.java (100%) create mode 100644 mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/package-info.java rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/WillMessageHandler.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/package-info.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/package-info.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/MQTTBrokerProtocolMethodProcessor.java (99%) create mode 100644 mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/package-info.java rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/AbstractQosPublishHandler.java (98%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos0PublishHandler.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos1PublishHandler.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos2PublishHandler.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandler.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlers.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlersImpl.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/package-info.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTAdditionalServlet.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTServiceServlet.java (100%) create mode 100644 mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/package-info.java rename {mqtt-impl => mqtt-broker}/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java (100%) rename {mqtt-impl => mqtt-broker}/src/main/resources/META-INF/services/additional_servlet.yml (100%) rename {mqtt-impl => mqtt-broker}/src/main/resources/META-INF/services/pulsar-protocol-handler.yml (100%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/MQTTSubscriptionManagerTest.java (100%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsCollectorTest.java (100%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsProviderTest.java (100%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MessageAckTrackerTest.java (94%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/ConfigurationUtilsTest.java (100%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/MqttMessageUtilsTest.java (100%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PacketIdGeneratorTest.java (94%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PulsarTopicUtilsTest.java (100%) rename {mqtt-impl => mqtt-broker}/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/TopicFilterImplTest.java (100%) rename {mqtt-impl => mqtt-broker}/src/test/resources/mqtt-test.conf (100%) rename {mqtt-impl => mqtt-broker}/src/test/resources/mtls/cel-test.txt (100%) rename {mqtt-impl => mqtt-broker}/src/test/resources/mtls/client-cert.pem (100%) rename {mqtt-impl => mqtt-broker}/src/test/resources/mtls/client.cer (100%) create mode 100644 mqtt-common/pom.xml rename {mqtt-impl => mqtt-common}/src/main/java-templates/io/streamnative/pulsar/handlers/mqtt/MopVersion.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/AbstractCommonProtocolMethodProcessor.java (99%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Connection.java (98%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Constants.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonConfiguration.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonInboundHandler.java (88%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTConnectionManager.java (100%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor => mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common}/ProtocolMethodProcessor.java (95%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilter.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilterImpl.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineAdapterHandler.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineHandler.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterDecoder.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterEncoder.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterMessage.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/MQTTAuthenticationService.java (88%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/event/AutoSubscribeHandler.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/event/DisableEventCenter.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/event/PulsarEventCenter.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/event/PulsarEventCenterImpl.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/event/PulsarEventListener.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/event/PulsarTopicChangeListener.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/event/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/MQTTAuthException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/MQTTDuplicatedSubscriptionException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/MQTTNoMatchingSubscriberException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/MQTTNoSubscriptionExistedException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/MQTTServerException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/MQTTTopicAliasExceedsLimitException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/MQTTTopicAliasNotFoundException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/MQTTTopicNotExistedException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/restrictions/InvalidReceiveMaximumException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/restrictions/InvalidSessionExpireIntervalException.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/exception/restrictions/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/MqttPropertyUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/ack/MqttAck.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/ack/MqttConnectAck.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/ack/MqttDisconnectAck.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/ack/MqttPubAck.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/ack/MqttSubAck.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/ack/MqttUnsubAck.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/ack/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/MqttReasonCode.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt3/Mqtt3ConnReasonCode.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt3/Mqtt3SubReasonCode.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt3/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt5/Mqtt5ConnReasonCode.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt5/Mqtt5DisConnReasonCode.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt5/Mqtt5PubReasonCode.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt5/Mqtt5SubReasonCode.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt5/Mqtt5UnsubReasonCode.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/mqtt5/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/codes/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/properties/PulsarProperties.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/messages/properties/package-info.java (100%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl => mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/mqtt5}/PacketIdGenerator.java (95%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/mqtt5/RetainedMessageHandler.java (100%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl => mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/mqtt5}/TopicAliasManager.java (98%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl => mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/mqtt5}/TopicSubscriptionManager.java (98%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/mqtt5/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/mqtt5/restrictions/ClientRestrictions.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/mqtt5/restrictions/ServerRestrictions.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/mqtt5/restrictions/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKClientKeyManager.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKConfiguration.java (87%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKey.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKeyStore.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKServerKeyManager.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ActionType.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ConnectEvent.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/DisabledSystemEventService.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventListener.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventType.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/LastWillMessageEvent.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MQTTEventSystemTopicClient.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEvent.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEventUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/PSKEvent.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/RetainedMessageEvent.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SourceEvent.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemEventService.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemTopicBasedSystemEventService.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/package-info.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/ConfigurationUtils.java (94%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/EventParserUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/FutureUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MessageBuilder.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttMessageUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/NettyUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/Paths.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/PulsarTopicUtils.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/RetainedMessage.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/WillMessage.java (100%) rename {mqtt-impl => mqtt-common}/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/package-info.java (100%) create mode 100644 mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java delete mode 100644 mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTInboundHandler.java delete mode 100644 mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/package-info.java delete mode 100644 mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/package-info.java create mode 100644 mqtt-proxy/pom.xml rename {mqtt-impl => mqtt-proxy}/src/main/java/io/streamnative/oidc/broker/common/OIDCConstants.java (100%) rename {mqtt-impl => mqtt-proxy}/src/main/java/io/streamnative/oidc/broker/common/OIDCPoolResources.java (100%) rename {mqtt-impl => mqtt-proxy}/src/main/java/io/streamnative/oidc/broker/common/package-info.java (100%) rename {mqtt-impl => mqtt-proxy}/src/main/java/io/streamnative/oidc/broker/common/pojo/Pool.java (100%) rename {mqtt-impl => mqtt-proxy}/src/main/java/io/streamnative/oidc/broker/common/utils/Paths.java (100%) create mode 100644 mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java rename {mqtt-impl => mqtt-proxy}/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyConfiguration.java (93%) create mode 100644 mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyProtocolHandler.java rename {mqtt-impl => mqtt-proxy}/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyService.java (69%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy}/authentication/mtls/AuthRequest.java (91%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy}/authentication/mtls/AuthenticationProviderMTls.java (99%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy}/authentication/mtls/ExpressionCompiler.java (97%) create mode 100644 mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/package-info.java create mode 100644 mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/package-info.java rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel}/AdapterChannel.java (95%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel}/MQTTProxyAdapter.java (96%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel}/MQTTProxyChannelInitializer.java (95%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel}/MQTTProxyInboundHandler.java (85%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel}/package-info.java (90%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler}/LookupHandler.java (94%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler}/PulsarServiceLookupHandler.java (98%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler}/package-info.java (90%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl}/MQTTProxyException.java (93%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl}/MQTTProxyProtocolMethodProcessor.java (98%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl}/MessageAckTracker.java (96%) rename {mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest => mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl}/package-info.java (91%) rename {mqtt-impl => mqtt-proxy}/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/package-info.java (100%) create mode 100644 mqtt-proxy/src/main/resources/META-INF/services/pulsar-protocol-handler.yml rename {mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/common => mqtt-proxy/src/test/java/io/streamnative/pulsar/handlers/mqtt/proxy}/authentication/mtls/AuthenticationProviderMTlsTest.java (99%) create mode 100644 mqtt-proxy/src/test/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MessageAckTrackerTest.java create mode 100644 mqtt-proxy/src/test/resources/mqtt-test.conf create mode 100644 mqtt-proxy/src/test/resources/mtls/cel-test.txt create mode 100644 mqtt-proxy/src/test/resources/mtls/client-cert.pem create mode 100644 mqtt-proxy/src/test/resources/mtls/client.cer diff --git a/.ci/Dockerfile b/.ci/Dockerfile index 8761fae95..6117a2671 100644 --- a/.ci/Dockerfile +++ b/.ci/Dockerfile @@ -6,4 +6,4 @@ ARG MOP_VERSION USER root RUN rm -rf /pulsar/protocols/pulsar-protocol-handler-mqtt-*.nar -COPY ../mqtt-impl/target/pulsar-protocol-handler-mqtt-${MOP_VERSION}.nar /pulsar/protocols \ No newline at end of file +COPY ../mqtt-broker/target/pulsar-protocol-handler-mqtt-${MOP_VERSION}.nar /pulsar/protocols \ No newline at end of file diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 3b74a0051..ef1426bba 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -61,7 +61,7 @@ jobs: id: list-test run: | TESTS=`find tests/src/test/java/io/streamnative/pulsar/handlers/mqtt \ - mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt -name "*Test.java" | \ + mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt -name "*Test.java" | \ awk -F "/" '{ print $NF }' | \ awk -F "." '{ print $1 }' | \ jq -R -s -c 'split("\n") | map(select(. != ""))'` @@ -146,7 +146,7 @@ jobs: - name: Download jacoco artifact uses: actions/download-artifact@v3 with: - path: mqtt-impl/target + path: mqtt-broker/target - name: Merge jacoco report run: mvn jacoco:merge diff --git a/README.md b/README.md index 2e1730584..2021178ab 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ MQTT-on-Pulsar (aka MoP) is developed to support MQTT protocol natively on Apach 3. The NAR file can be found at this location. ```bash - ./mqtt-impl/target/pulsar-protocol-handler-mqtt-${version}.nar + ./mqtt-broker/target/pulsar-protocol-handler-mqtt-${version}.nar ``` ### Install MoP protocol handler diff --git a/mqtt-impl/pom.xml b/mqtt-broker/pom.xml similarity index 88% rename from mqtt-impl/pom.xml rename to mqtt-broker/pom.xml index 4e29faef1..2293b02ff 100644 --- a/mqtt-impl/pom.xml +++ b/mqtt-broker/pom.xml @@ -27,6 +27,13 @@ StreamNative :: Pulsar Protocol Handler :: MQTT MQTT on Pulsar implemented using Pulsar Protocol Handler + + + io.streamnative.pulsar.handlers + pulsar-protocol-handler-mqtt-proxy + ${project.version} + + diff --git a/mqtt-impl/src/assemble/bin.xml b/mqtt-broker/src/assemble/bin.xml similarity index 100% rename from mqtt-impl/src/assemble/bin.xml rename to mqtt-broker/src/assemble/bin.xml diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTProtocolHandler.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTProtocolHandler.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTProtocolHandler.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTProtocolHandler.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTServerConfiguration.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTServerConfiguration.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTServerConfiguration.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTServerConfiguration.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTService.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTService.java similarity index 95% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTService.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTService.java index 7de451c6d..a341c27d3 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTService.java +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTService.java @@ -93,7 +93,9 @@ public MQTTService(BrokerService brokerService, MQTTServerConfiguration serverCo this.brokerService = brokerService; this.pulsarService = brokerService.pulsar(); this.serverConfiguration = serverConfiguration; - this.pskConfiguration = new PSKConfiguration(serverConfiguration); + this.pskConfiguration = new PSKConfiguration(serverConfiguration.getMqttTlsPskIdentityHint(), + serverConfiguration.getMqttTlsPskIdentity(), serverConfiguration.getMqttTlsPskIdentityFile(), + serverConfiguration.getMqttTlsProtocols(), serverConfiguration.getMqttTlsCiphers()); this.authorizationService = brokerService.getAuthorizationService(); this.bundleOwnershipListener = new MQTTNamespaceBundleOwnershipListener(pulsarService.getNamespaceService()); this.metricsCollector = new MQTTMetricsCollector(serverConfiguration); @@ -101,8 +103,7 @@ public MQTTService(BrokerService brokerService, MQTTServerConfiguration serverCo this.pulsarService.addPrometheusRawMetricsProvider(metricsProvider); this.authenticationService = serverConfiguration.isMqttAuthenticationEnabled() ? new MQTTAuthenticationService(brokerService, - serverConfiguration.getMqttAuthenticationMethods(), - serverConfiguration.isMqttProxyMTlsAuthenticationEnabled()) : null; + serverConfiguration.getMqttAuthenticationMethods()) : null; this.connectionManager = new MQTTConnectionManager(pulsarService.getAdvertisedAddress()); this.subscriptionManager = new MQTTSubscriptionManager(); if (getServerConfiguration().isMqttProxyEnabled()) { diff --git a/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTBrokerInboundHandler.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTBrokerInboundHandler.java new file mode 100644 index 000000000..57a33b602 --- /dev/null +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTBrokerInboundHandler.java @@ -0,0 +1,60 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.broker.channel; + +import static com.google.common.base.Preconditions.checkArgument; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.streamnative.pulsar.handlers.mqtt.broker.MQTTService; +import io.streamnative.pulsar.handlers.mqtt.broker.processor.MQTTBrokerProtocolMethodProcessor; +import io.streamnative.pulsar.handlers.mqtt.common.MQTTCommonInboundHandler; +import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; +import java.util.concurrent.CompletableFuture; +import lombok.extern.slf4j.Slf4j; + +/** + * MQTT in bound handler. + */ +@Sharable +@Slf4j +public class MQTTBrokerInboundHandler extends MQTTCommonInboundHandler { + + public static final String NAME = "handler"; + + private final MQTTService mqttService; + + public MQTTBrokerInboundHandler(MQTTService mqttService) { + this.mqttService = mqttService; + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + super.channelActive(ctx); + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object message) { + checkArgument(message instanceof MqttAdapterMessage); + MqttAdapterMessage adapterMsg = (MqttAdapterMessage) message; + processors.computeIfAbsent(adapterMsg.getClientId(), key -> { + MQTTBrokerProtocolMethodProcessor p = new MQTTBrokerProtocolMethodProcessor(mqttService, ctx); + CompletableFuture inactiveFuture = p.getInactiveFuture(); + inactiveFuture.whenComplete((id, ex) -> { + processors.remove(adapterMsg.getClientId()); + }); + return p; + }); + super.channelRead(ctx, message); + } +} diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTChannelInitializer.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTChannelInitializer.java similarity index 98% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTChannelInitializer.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTChannelInitializer.java index 2f4d0bd0c..399786b7f 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTChannelInitializer.java +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTChannelInitializer.java @@ -98,7 +98,7 @@ public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(MqttAdapterEncoder.NAME, MqttAdapterEncoder.INSTANCE); // Handler ch.pipeline().addLast(CombineAdapterHandler.NAME, new CombineAdapterHandler()); - ch.pipeline().addLast(MQTTInboundHandler.NAME, new MQTTInboundHandler(mqttService)); + ch.pipeline().addLast(MQTTBrokerInboundHandler.NAME, new MQTTBrokerInboundHandler(mqttService)); } /** diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTServerCnx.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTServerCnx.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTServerCnx.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTServerCnx.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/package-info.java similarity index 88% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/package-info.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/package-info.java index 57b0a6fa4..f401e4b65 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/package-info.java +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/package-info.java @@ -11,4 +11,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.common.authentication.mtls; \ No newline at end of file +package io.streamnative.pulsar.handlers.mqtt.broker.channel; \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/MqttWebSocketCodec.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/MqttWebSocketCodec.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/MqttWebSocketCodec.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/MqttWebSocketCodec.java diff --git a/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/package-info.java new file mode 100644 index 000000000..bbaeac08e --- /dev/null +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/package-info.java @@ -0,0 +1,14 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.broker.codec; \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTNamespaceBundleOwnershipListener.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTNamespaceBundleOwnershipListener.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTNamespaceBundleOwnershipListener.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTNamespaceBundleOwnershipListener.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTSubscriptionManager.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTSubscriptionManager.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTSubscriptionManager.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTSubscriptionManager.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTTopicOwnershipListener.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTTopicOwnershipListener.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTTopicOwnershipListener.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/MQTTTopicOwnershipListener.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/PulsarMessageConverter.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/PulsarMessageConverter.java similarity index 99% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/PulsarMessageConverter.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/PulsarMessageConverter.java index 6d645fd52..5f22800e6 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/PulsarMessageConverter.java +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/PulsarMessageConverter.java @@ -24,6 +24,7 @@ import io.netty.handler.codec.mqtt.MqttQoS; import io.netty.util.concurrent.FastThreadLocal; import io.streamnative.pulsar.handlers.mqtt.broker.MQTTServerConfiguration; +import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.PacketIdGenerator; import io.streamnative.pulsar.handlers.mqtt.common.utils.MessageBuilder; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MQTTConsumer.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MQTTConsumer.java similarity index 99% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MQTTConsumer.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MQTTConsumer.java index 0c83102d2..f9de5d552 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MQTTConsumer.java +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MQTTConsumer.java @@ -20,11 +20,11 @@ import io.netty.handler.codec.mqtt.MqttQoS; import io.netty.util.concurrent.Future; import io.streamnative.pulsar.handlers.mqtt.broker.channel.MQTTServerCnx; -import io.streamnative.pulsar.handlers.mqtt.broker.impl.PacketIdGenerator; import io.streamnative.pulsar.handlers.mqtt.broker.impl.PulsarMessageConverter; import io.streamnative.pulsar.handlers.mqtt.broker.metric.MQTTMetricsCollector; import io.streamnative.pulsar.handlers.mqtt.common.Connection; import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; +import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.PacketIdGenerator; import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.restrictions.ClientRestrictions; import io.streamnative.pulsar.handlers.mqtt.common.utils.PulsarTopicUtils; import java.util.Collections; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MessagePublishContext.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MessagePublishContext.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MessagePublishContext.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/MessagePublishContext.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacket.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacket.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacket.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacket.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainer.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainer.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainer.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainer.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainerImpl.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainerImpl.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainerImpl.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/OutstandingPacketContainerImpl.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/package-info.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/consumer/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/package-info.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/impl/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsCollector.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsCollector.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsCollector.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsCollector.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsProvider.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsProvider.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsProvider.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/MQTTMetricsProvider.java diff --git a/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/package-info.java new file mode 100644 index 000000000..718d8a309 --- /dev/null +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/package-info.java @@ -0,0 +1,14 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.broker.metric; \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/WillMessageHandler.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/WillMessageHandler.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/WillMessageHandler.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/WillMessageHandler.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/package-info.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/mqtt5/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/package-info.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/MQTTBrokerProtocolMethodProcessor.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/MQTTBrokerProtocolMethodProcessor.java similarity index 99% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/MQTTBrokerProtocolMethodProcessor.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/MQTTBrokerProtocolMethodProcessor.java index 630254d13..d8c20ae53 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/MQTTBrokerProtocolMethodProcessor.java +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/MQTTBrokerProtocolMethodProcessor.java @@ -31,7 +31,6 @@ import io.streamnative.pulsar.handlers.mqtt.broker.MQTTService; import io.streamnative.pulsar.handlers.mqtt.broker.channel.MQTTServerCnx; import io.streamnative.pulsar.handlers.mqtt.broker.impl.MQTTSubscriptionManager; -import io.streamnative.pulsar.handlers.mqtt.broker.impl.PacketIdGenerator; import io.streamnative.pulsar.handlers.mqtt.broker.impl.consumer.MQTTConsumer; import io.streamnative.pulsar.handlers.mqtt.broker.impl.consumer.OutstandingPacket; import io.streamnative.pulsar.handlers.mqtt.broker.impl.consumer.OutstandingPacketContainer; @@ -58,6 +57,7 @@ import io.streamnative.pulsar.handlers.mqtt.common.messages.codes.mqtt5.Mqtt5PubReasonCode; import io.streamnative.pulsar.handlers.mqtt.common.messages.codes.mqtt5.Mqtt5UnsubReasonCode; import io.streamnative.pulsar.handlers.mqtt.common.messages.properties.PulsarProperties; +import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.PacketIdGenerator; import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.RetainedMessageHandler; import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.restrictions.ClientRestrictions; import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.restrictions.ServerRestrictions; diff --git a/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/package-info.java new file mode 100644 index 000000000..f02687891 --- /dev/null +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/package-info.java @@ -0,0 +1,14 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.broker.processor; \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/AbstractQosPublishHandler.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/AbstractQosPublishHandler.java similarity index 98% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/AbstractQosPublishHandler.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/AbstractQosPublishHandler.java index 265553ccc..eadb807e3 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/AbstractQosPublishHandler.java +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/AbstractQosPublishHandler.java @@ -18,7 +18,6 @@ import io.netty.handler.codec.mqtt.MqttPublishMessage; import io.streamnative.pulsar.handlers.mqtt.broker.MQTTServerConfiguration; import io.streamnative.pulsar.handlers.mqtt.broker.MQTTService; -import io.streamnative.pulsar.handlers.mqtt.broker.impl.TopicAliasManager; import io.streamnative.pulsar.handlers.mqtt.broker.impl.consumer.MessagePublishContext; import io.streamnative.pulsar.handlers.mqtt.common.Connection; import io.streamnative.pulsar.handlers.mqtt.common.exception.MQTTNoMatchingSubscriberException; @@ -26,6 +25,7 @@ import io.streamnative.pulsar.handlers.mqtt.common.exception.MQTTTopicAliasNotFoundException; import io.streamnative.pulsar.handlers.mqtt.common.messages.MqttPropertyUtils; import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.RetainedMessageHandler; +import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.TopicAliasManager; import io.streamnative.pulsar.handlers.mqtt.common.utils.PulsarTopicUtils; import java.util.Optional; import java.util.concurrent.CompletableFuture; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos0PublishHandler.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos0PublishHandler.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos0PublishHandler.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos0PublishHandler.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos1PublishHandler.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos1PublishHandler.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos1PublishHandler.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos1PublishHandler.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos2PublishHandler.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos2PublishHandler.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos2PublishHandler.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/Qos2PublishHandler.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandler.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandler.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandler.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandler.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlers.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlers.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlers.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlers.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlersImpl.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlersImpl.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlersImpl.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/QosPublishHandlersImpl.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/package-info.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/qos/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTAdditionalServlet.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTAdditionalServlet.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTAdditionalServlet.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTAdditionalServlet.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTServiceServlet.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTServiceServlet.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTServiceServlet.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/MQTTServiceServlet.java diff --git a/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/package-info.java new file mode 100644 index 000000000..35c55a5e3 --- /dev/null +++ b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/package-info.java @@ -0,0 +1,14 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.broker.rest; \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java b/mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java rename to mqtt-broker/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java diff --git a/mqtt-impl/src/main/resources/META-INF/services/additional_servlet.yml b/mqtt-broker/src/main/resources/META-INF/services/additional_servlet.yml similarity index 100% rename from mqtt-impl/src/main/resources/META-INF/services/additional_servlet.yml rename to mqtt-broker/src/main/resources/META-INF/services/additional_servlet.yml diff --git a/mqtt-impl/src/main/resources/META-INF/services/pulsar-protocol-handler.yml b/mqtt-broker/src/main/resources/META-INF/services/pulsar-protocol-handler.yml similarity index 100% rename from mqtt-impl/src/main/resources/META-INF/services/pulsar-protocol-handler.yml rename to mqtt-broker/src/main/resources/META-INF/services/pulsar-protocol-handler.yml diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/MQTTSubscriptionManagerTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/MQTTSubscriptionManagerTest.java similarity index 100% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/MQTTSubscriptionManagerTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/MQTTSubscriptionManagerTest.java diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsCollectorTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsCollectorTest.java similarity index 100% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsCollectorTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsCollectorTest.java diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsProviderTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsProviderTest.java similarity index 100% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsProviderTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MQTTMetricsProviderTest.java diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MessageAckTrackerTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MessageAckTrackerTest.java similarity index 94% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MessageAckTrackerTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MessageAckTrackerTest.java index b904aa9de..17f3d9f06 100644 --- a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MessageAckTrackerTest.java +++ b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MessageAckTrackerTest.java @@ -15,7 +15,7 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import io.streamnative.pulsar.handlers.mqtt.proxy.MessageAckTracker; +import io.streamnative.pulsar.handlers.mqtt.proxy.impl.MessageAckTracker; import org.testng.annotations.Test; public class MessageAckTrackerTest { diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/ConfigurationUtilsTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/ConfigurationUtilsTest.java similarity index 100% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/ConfigurationUtilsTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/ConfigurationUtilsTest.java diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/MqttMessageUtilsTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/MqttMessageUtilsTest.java similarity index 100% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/MqttMessageUtilsTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/MqttMessageUtilsTest.java diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PacketIdGeneratorTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PacketIdGeneratorTest.java similarity index 94% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PacketIdGeneratorTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PacketIdGeneratorTest.java index d6aaa3ea5..2d6cd4d2b 100644 --- a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PacketIdGeneratorTest.java +++ b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PacketIdGeneratorTest.java @@ -14,7 +14,7 @@ package io.streamnative.pulsar.handlers.mqtt.untils; -import io.streamnative.pulsar.handlers.mqtt.broker.impl.PacketIdGenerator; +import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.PacketIdGenerator; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PulsarTopicUtilsTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PulsarTopicUtilsTest.java similarity index 100% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PulsarTopicUtilsTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/PulsarTopicUtilsTest.java diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/TopicFilterImplTest.java b/mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/TopicFilterImplTest.java similarity index 100% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/TopicFilterImplTest.java rename to mqtt-broker/src/test/java/io/streamnative/pulsar/handlers/mqtt/untils/TopicFilterImplTest.java diff --git a/mqtt-impl/src/test/resources/mqtt-test.conf b/mqtt-broker/src/test/resources/mqtt-test.conf similarity index 100% rename from mqtt-impl/src/test/resources/mqtt-test.conf rename to mqtt-broker/src/test/resources/mqtt-test.conf diff --git a/mqtt-impl/src/test/resources/mtls/cel-test.txt b/mqtt-broker/src/test/resources/mtls/cel-test.txt similarity index 100% rename from mqtt-impl/src/test/resources/mtls/cel-test.txt rename to mqtt-broker/src/test/resources/mtls/cel-test.txt diff --git a/mqtt-impl/src/test/resources/mtls/client-cert.pem b/mqtt-broker/src/test/resources/mtls/client-cert.pem similarity index 100% rename from mqtt-impl/src/test/resources/mtls/client-cert.pem rename to mqtt-broker/src/test/resources/mtls/client-cert.pem diff --git a/mqtt-impl/src/test/resources/mtls/client.cer b/mqtt-broker/src/test/resources/mtls/client.cer similarity index 100% rename from mqtt-impl/src/test/resources/mtls/client.cer rename to mqtt-broker/src/test/resources/mtls/client.cer diff --git a/mqtt-common/pom.xml b/mqtt-common/pom.xml new file mode 100644 index 000000000..707ea52b6 --- /dev/null +++ b/mqtt-common/pom.xml @@ -0,0 +1,27 @@ + + + + + pulsar-protocol-handler-mqtt-parent + io.streamnative.pulsar.handlers + 3.4.0-SNAPSHOT + + 4.0.0 + pulsar-protocol-handler-mqtt-common + \ No newline at end of file diff --git a/mqtt-impl/src/main/java-templates/io/streamnative/pulsar/handlers/mqtt/MopVersion.java b/mqtt-common/src/main/java-templates/io/streamnative/pulsar/handlers/mqtt/MopVersion.java similarity index 100% rename from mqtt-impl/src/main/java-templates/io/streamnative/pulsar/handlers/mqtt/MopVersion.java rename to mqtt-common/src/main/java-templates/io/streamnative/pulsar/handlers/mqtt/MopVersion.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/AbstractCommonProtocolMethodProcessor.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/AbstractCommonProtocolMethodProcessor.java similarity index 99% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/AbstractCommonProtocolMethodProcessor.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/AbstractCommonProtocolMethodProcessor.java index 69e429c5a..176b789b4 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/AbstractCommonProtocolMethodProcessor.java +++ b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/AbstractCommonProtocolMethodProcessor.java @@ -22,7 +22,6 @@ import io.netty.handler.codec.mqtt.MqttProperties; import io.netty.handler.codec.mqtt.MqttReasonCodeAndPropertiesVariableHeader; import io.netty.handler.ssl.SslHandler; -import io.streamnative.pulsar.handlers.mqtt.broker.processor.ProtocolMethodProcessor; import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; import io.streamnative.pulsar.handlers.mqtt.common.authentication.MQTTAuthenticationService; import io.streamnative.pulsar.handlers.mqtt.common.exception.MQTTAuthException; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Connection.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Connection.java similarity index 98% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Connection.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Connection.java index fdc0a73bf..8f8a0417d 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Connection.java +++ b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Connection.java @@ -28,14 +28,13 @@ import io.netty.handler.codec.mqtt.MqttProperties; import io.netty.handler.codec.mqtt.MqttQoS; import io.netty.handler.timeout.IdleStateHandler; -import io.streamnative.pulsar.handlers.mqtt.broker.impl.TopicAliasManager; -import io.streamnative.pulsar.handlers.mqtt.broker.impl.TopicSubscriptionManager; -import io.streamnative.pulsar.handlers.mqtt.broker.processor.ProtocolMethodProcessor; import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; import io.streamnative.pulsar.handlers.mqtt.common.exception.restrictions.InvalidSessionExpireIntervalException; import io.streamnative.pulsar.handlers.mqtt.common.messages.ack.MqttAck; import io.streamnative.pulsar.handlers.mqtt.common.messages.ack.MqttConnectAck; import io.streamnative.pulsar.handlers.mqtt.common.messages.codes.mqtt5.Mqtt5DisConnReasonCode; +import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.TopicAliasManager; +import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.TopicSubscriptionManager; import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.restrictions.ClientRestrictions; import io.streamnative.pulsar.handlers.mqtt.common.mqtt5.restrictions.ServerRestrictions; import io.streamnative.pulsar.handlers.mqtt.common.utils.FutureUtils; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Constants.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Constants.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Constants.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/Constants.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonConfiguration.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonConfiguration.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonConfiguration.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonConfiguration.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonInboundHandler.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonInboundHandler.java similarity index 88% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonInboundHandler.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonInboundHandler.java index 87205ccb4..807e50f93 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonInboundHandler.java +++ b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTCommonInboundHandler.java @@ -14,6 +14,7 @@ package io.streamnative.pulsar.handlers.mqtt.common; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; import static io.streamnative.pulsar.handlers.mqtt.common.utils.MqttMessageUtils.checkState; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; @@ -23,14 +24,9 @@ import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; import io.netty.util.ReferenceCountUtil; -import io.streamnative.pulsar.handlers.mqtt.broker.MQTTService; -import io.streamnative.pulsar.handlers.mqtt.broker.processor.MQTTBrokerProtocolMethodProcessor; -import io.streamnative.pulsar.handlers.mqtt.broker.processor.ProtocolMethodProcessor; import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; import io.streamnative.pulsar.handlers.mqtt.common.utils.NettyUtils; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; /** @@ -42,9 +38,6 @@ public class MQTTCommonInboundHandler extends ChannelInboundHandlerAdapter { public static final String NAME = "InboundHandler"; - @Setter - protected MQTTService mqttService; - protected final ConcurrentHashMap processors = new ConcurrentHashMap<>(); @Override @@ -52,15 +45,9 @@ public void channelRead(ChannelHandlerContext ctx, Object message) { checkArgument(message instanceof MqttAdapterMessage); MqttAdapterMessage adapterMsg = (MqttAdapterMessage) message; MqttMessage mqttMessage = adapterMsg.getMqttMessage(); - final ProtocolMethodProcessor processor = processors.computeIfAbsent(adapterMsg.getClientId(), key -> { - MQTTBrokerProtocolMethodProcessor p = new MQTTBrokerProtocolMethodProcessor(mqttService, ctx); - CompletableFuture inactiveFuture = p.getInactiveFuture(); - inactiveFuture.whenComplete((id, ex) -> { - processors.remove(adapterMsg.getClientId()); - }); - return p; - }); + final ProtocolMethodProcessor processor = processors.get(adapterMsg.getClientId()); try { + checkNotNull(processor); checkState(mqttMessage); MqttMessageType messageType = mqttMessage.fixedHeader().messageType(); if (log.isDebugEnabled()) { diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTConnectionManager.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTConnectionManager.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTConnectionManager.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/MQTTConnectionManager.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/ProtocolMethodProcessor.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/ProtocolMethodProcessor.java similarity index 95% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/ProtocolMethodProcessor.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/ProtocolMethodProcessor.java index d1f6938e7..e89e88c76 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/ProtocolMethodProcessor.java +++ b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/ProtocolMethodProcessor.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.broker.processor; +package io.streamnative.pulsar.handlers.mqtt.common; import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilter.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilter.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilter.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilter.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilterImpl.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilterImpl.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilterImpl.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/TopicFilterImpl.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineAdapterHandler.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineAdapterHandler.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineAdapterHandler.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineAdapterHandler.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineHandler.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineHandler.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineHandler.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/CombineHandler.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterDecoder.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterDecoder.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterDecoder.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterDecoder.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterEncoder.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterEncoder.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterEncoder.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterEncoder.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterMessage.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterMessage.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterMessage.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MqttAdapterMessage.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/package-info.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/package-info.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/MQTTAuthenticationService.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/MQTTAuthenticationService.java similarity index 88% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/MQTTAuthenticationService.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/MQTTAuthenticationService.java index e1ecac1a2..c4cfa26ce 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/MQTTAuthenticationService.java +++ b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/MQTTAuthenticationService.java @@ -18,7 +18,6 @@ import static io.streamnative.pulsar.handlers.mqtt.common.Constants.AUTH_TOKEN; import io.netty.handler.codec.mqtt.MqttConnectMessage; import io.netty.handler.codec.mqtt.MqttConnectPayload; -import io.streamnative.pulsar.handlers.mqtt.common.authentication.mtls.AuthenticationProviderMTls; import io.streamnative.pulsar.handlers.mqtt.common.utils.MqttMessageUtils; import java.util.HashMap; import java.util.List; @@ -46,14 +45,7 @@ public class MQTTAuthenticationService { @Getter private final Map authenticationProviders; - private final BrokerService brokerService; - - private final boolean mqttProxyMTlsAuthenticationEnabled; - - public MQTTAuthenticationService(BrokerService brokerService, List authenticationMethods, boolean - mqttProxyMTlsAuthenticationEnabled) { - this.brokerService = brokerService; - this.mqttProxyMTlsAuthenticationEnabled = mqttProxyMTlsAuthenticationEnabled; + public MQTTAuthenticationService(BrokerService brokerService, List authenticationMethods) { this.authenticationService = brokerService.getAuthenticationService(); this.authenticationProviders = getAuthenticationProviders(authenticationMethods); } @@ -68,15 +60,7 @@ private Map getAuthenticationProviders(List protocols, Set ciphers) { + setIdentityHint(identityHint); + setIdentity(identity); + setIdentityFile(identityFile); + setProtocols(protocols); + setCiphers(ciphers); } public void setIdentityFile(String identityFile) { diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKey.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKey.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKey.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKey.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKeyStore.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKeyStore.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKeyStore.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKSecretKeyStore.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKServerKeyManager.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKServerKeyManager.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKServerKeyManager.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKServerKeyManager.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKUtils.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/PSKUtils.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/package-info.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/package-info.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/psk/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ActionType.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ActionType.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ActionType.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ActionType.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ConnectEvent.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ConnectEvent.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ConnectEvent.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/ConnectEvent.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/DisabledSystemEventService.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/DisabledSystemEventService.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/DisabledSystemEventService.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/DisabledSystemEventService.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventListener.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventListener.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventListener.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventListener.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventType.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventType.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventType.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/EventType.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/LastWillMessageEvent.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/LastWillMessageEvent.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/LastWillMessageEvent.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/LastWillMessageEvent.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MQTTEventSystemTopicClient.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MQTTEventSystemTopicClient.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MQTTEventSystemTopicClient.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MQTTEventSystemTopicClient.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEvent.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEvent.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEvent.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEvent.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEventUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEventUtils.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEventUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/MqttEventUtils.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/PSKEvent.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/PSKEvent.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/PSKEvent.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/PSKEvent.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/RetainedMessageEvent.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/RetainedMessageEvent.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/RetainedMessageEvent.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/RetainedMessageEvent.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SourceEvent.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SourceEvent.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SourceEvent.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SourceEvent.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemEventService.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemEventService.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemEventService.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemEventService.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemTopicBasedSystemEventService.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemTopicBasedSystemEventService.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemTopicBasedSystemEventService.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/SystemTopicBasedSystemEventService.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/package-info.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/package-info.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/systemtopic/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/ConfigurationUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/ConfigurationUtils.java similarity index 94% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/ConfigurationUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/ConfigurationUtils.java index 5812162af..461f6f249 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/ConfigurationUtils.java +++ b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/ConfigurationUtils.java @@ -42,7 +42,9 @@ public final class ConfigurationUtils { public static final String PROTOCOL_NAME = "mqtt"; + public static final String PROTOCOL_PROXY_NAME = "mqtt-proxy"; public static final String PLAINTEXT_PREFIX = "mqtt://"; + public static final String PROXY_PREFIX = "mqtt-proxy://"; public static final String SSL_PREFIX = "mqtt+ssl://"; public static final String SSL_PSK_PREFIX = "mqtt+ssl+psk://"; public static final String WS_PLAINTEXT_PREFIX = "ws://"; @@ -52,6 +54,9 @@ public final class ConfigurationUtils { public static final String LISTENER_PATTERN = "^((mqtt)(\\+ssl)?(\\+psk)?|(ws)(\\+ssl)?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-0-9+]"; + public static final String PROXY_LISTENER_PATTERN = + "^(mqtt-proxy)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-0-9+]"; + /** * Creates PulsarConfiguration and loads it with populated attribute values loaded from provided property file. * @@ -158,6 +163,13 @@ public static int getListenerPort(String listener) { return Integer.parseInt(listener.substring(lastIndex + 1)); } + public static int getProxyListenerPort(String listener) { + checkArgument(listener.matches(PROXY_LISTENER_PATTERN), "proxy listener not match pattern"); + + int lastIndex = listener.lastIndexOf(':'); + return Integer.parseInt(listener.substring(lastIndex + 1)); + } + private ConfigurationUtils() {} /** @@ -244,4 +256,5 @@ private static String listToString(Object fieldValue) { return Joiner.on(LISTENER_DEL).join(list); } + } diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/EventParserUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/EventParserUtils.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/EventParserUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/EventParserUtils.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/FutureUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/FutureUtils.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/FutureUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/FutureUtils.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MessageBuilder.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MessageBuilder.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MessageBuilder.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MessageBuilder.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttMessageUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttMessageUtils.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttMessageUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttMessageUtils.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttUtils.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/MqttUtils.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/NettyUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/NettyUtils.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/NettyUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/NettyUtils.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/Paths.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/Paths.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/Paths.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/Paths.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/PulsarTopicUtils.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/PulsarTopicUtils.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/PulsarTopicUtils.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/PulsarTopicUtils.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/RetainedMessage.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/RetainedMessage.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/RetainedMessage.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/RetainedMessage.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/WillMessage.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/WillMessage.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/WillMessage.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/WillMessage.java diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/package-info.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/package-info.java rename to mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/utils/package-info.java diff --git a/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java new file mode 100644 index 000000000..d5d6672e4 --- /dev/null +++ b/mqtt-common/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java @@ -0,0 +1,14 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt; \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTInboundHandler.java b/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTInboundHandler.java deleted file mode 100644 index 28d64e5d2..000000000 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/MQTTInboundHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Licensed 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 io.streamnative.pulsar.handlers.mqtt.broker.channel; - -import io.netty.channel.ChannelHandler.Sharable; -import io.netty.channel.ChannelHandlerContext; -import io.streamnative.pulsar.handlers.mqtt.broker.MQTTService; -import io.streamnative.pulsar.handlers.mqtt.common.MQTTCommonInboundHandler; -import lombok.extern.slf4j.Slf4j; -/** - * MQTT in bound handler. - */ -@Sharable -@Slf4j -public class MQTTInboundHandler extends MQTTCommonInboundHandler { - - public static final String NAME = "handler"; - - public MQTTInboundHandler(MQTTService mqttService) { - super.mqttService = mqttService; - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - super.channelActive(ctx); - } -} diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/package-info.java b/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/package-info.java deleted file mode 100644 index d457ba753..000000000 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/channel/package-info.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Licensed 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 info. - */ -package io.streamnative.pulsar.handlers.mqtt.broker.channel; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/package-info.java b/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/package-info.java deleted file mode 100644 index 27483b48a..000000000 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/processor/package-info.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Licensed 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 info. - */ -package io.streamnative.pulsar.handlers.mqtt.broker.processor; diff --git a/mqtt-proxy/pom.xml b/mqtt-proxy/pom.xml new file mode 100644 index 000000000..47fdb6df7 --- /dev/null +++ b/mqtt-proxy/pom.xml @@ -0,0 +1,58 @@ + + + + + pulsar-protocol-handler-mqtt-parent + io.streamnative.pulsar.handlers + 3.4.0-SNAPSHOT + + 4.0.0 + pulsar-protocol-handler-mqtt-proxy + + + + + io.streamnative.pulsar.handlers + pulsar-protocol-handler-mqtt-common + ${project.version} + + + + + + org.apache.nifi + nifi-nar-maven-plugin + 1.2.0 + true + + ${project.artifactId}-${project.version} + + + + default-nar + package + + nar + + + + + + + \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/OIDCConstants.java b/mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/OIDCConstants.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/OIDCConstants.java rename to mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/OIDCConstants.java diff --git a/mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/OIDCPoolResources.java b/mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/OIDCPoolResources.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/OIDCPoolResources.java rename to mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/OIDCPoolResources.java diff --git a/mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/package-info.java b/mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/package-info.java rename to mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/package-info.java diff --git a/mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/pojo/Pool.java b/mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/pojo/Pool.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/pojo/Pool.java rename to mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/pojo/Pool.java diff --git a/mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/utils/Paths.java b/mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/utils/Paths.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/oidc/broker/common/utils/Paths.java rename to mqtt-proxy/src/main/java/io/streamnative/oidc/broker/common/utils/Paths.java diff --git a/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java new file mode 100644 index 000000000..d5d6672e4 --- /dev/null +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/package-info.java @@ -0,0 +1,14 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt; \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyConfiguration.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyConfiguration.java similarity index 93% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyConfiguration.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyConfiguration.java index c1193a12f..ac09e4c9c 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyConfiguration.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyConfiguration.java @@ -29,6 +29,13 @@ public class MQTTProxyConfiguration extends MQTTCommonConfiguration { @Category private static final String CATEGORY_BROKER_DISCOVERY = "Broker Discovery"; + @FieldContext( + category = CATEGORY_MQTT, + required = true, + doc = "Listener for the MQTT Server." + ) + private String mqttProxyListeners = "mqtt://127.0.0.1:5682"; + @FieldContext( category = CATEGORY_BROKER_DISCOVERY, doc = "The service url points to the broker cluster" diff --git a/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyProtocolHandler.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyProtocolHandler.java new file mode 100644 index 000000000..6d86fc9f4 --- /dev/null +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyProtocolHandler.java @@ -0,0 +1,137 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.proxy; + +import static com.google.common.base.Preconditions.checkArgument; +import static io.streamnative.pulsar.handlers.mqtt.common.utils.ConfigurationUtils.LISTENER_DEL; +import static io.streamnative.pulsar.handlers.mqtt.common.utils.ConfigurationUtils.PROTOCOL_PROXY_NAME; +import static io.streamnative.pulsar.handlers.mqtt.common.utils.ConfigurationUtils.PROXY_PREFIX; +import static io.streamnative.pulsar.handlers.mqtt.common.utils.ConfigurationUtils.getProxyListenerPort; +import com.google.common.collect.ImmutableMap; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.socket.SocketChannel; +import io.netty.util.concurrent.DefaultThreadFactory; +import io.streamnative.pulsar.handlers.mqtt.common.utils.ConfigurationUtils; +import io.streamnative.pulsar.handlers.mqtt.proxy.channel.MQTTProxyChannelInitializer; +import java.net.InetSocketAddress; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.apache.pulsar.broker.ServiceConfiguration; +import org.apache.pulsar.broker.ServiceConfigurationUtils; +import org.apache.pulsar.broker.protocol.ProtocolHandler; +import org.apache.pulsar.broker.service.BrokerService; + +/** + * MQTT Protocol Handler load and run by Pulsar Service. + */ +@Slf4j +public class MQTTProxyProtocolHandler implements ProtocolHandler { + + @Getter + private MQTTProxyConfiguration proxyConfig; + + @Getter + private BrokerService brokerService; + + @Getter + private String bindAddress; + + private MQTTProxyService proxyService; + + private ScheduledExecutorService sslContextRefresher; + + @Override + public String protocolName() { + return PROTOCOL_PROXY_NAME; + } + + @Override + public boolean accept(String protocol) { + return PROTOCOL_PROXY_NAME.equals(protocol.toLowerCase()); + } + + @Override + public void initialize(ServiceConfiguration conf) throws Exception { + // init config + proxyConfig = ConfigurationUtils.create(conf.getProperties(), MQTTProxyConfiguration.class); + // We have to enable ack batch message individual. + proxyConfig.setAcknowledgmentAtBatchIndexLevelEnabled(true); + this.bindAddress = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(proxyConfig.getBindAddress()); + } + + @Override + public String getProtocolDataToAdvertise() { + if (log.isDebugEnabled()) { + log.debug("Get configured listener: {}", proxyConfig.getMqttProxyListeners()); + } + return proxyConfig.getMqttProxyListeners(); + } + + @Override + public void start(BrokerService brokerService) { + this.brokerService = brokerService; + try { + proxyService = new MQTTProxyService(brokerService, proxyConfig); + proxyService.start0(); + log.info("Start MQTT proxy service "); + } catch (Exception ex) { + log.error("Failed to start MQTT proxy service.", ex); + } + } + + @Override + public Map> newChannelInitializers() { + try { + checkArgument(proxyConfig != null); + checkArgument(proxyConfig.getMqttProxyListeners() != null); + checkArgument(brokerService != null); + + this.sslContextRefresher = Executors.newSingleThreadScheduledExecutor( + new DefaultThreadFactory("mop-ssl-context-refresher")); + + String listeners = proxyConfig.getMqttProxyListeners(); + String[] parts = listeners.split(LISTENER_DEL); + ImmutableMap.Builder> builder = + ImmutableMap.>builder(); + + for (String listener: parts) { + if (listener.startsWith(PROXY_PREFIX)) { + builder.put( + new InetSocketAddress(brokerService.pulsar().getBindAddress(), + getProxyListenerPort(listener)), + new MQTTProxyChannelInitializer( + proxyService, proxyConfig, false, false, sslContextRefresher)); + } + } + return builder.build(); + } catch (Exception e) { + log.error("MQTTProtocolHandler newChannelInitializers failed with", e); + return null; + } + } + + @Override + public void close() { + if (sslContextRefresher != null) { + sslContextRefresher.shutdownNow(); + } + if (proxyService != null) { + proxyService.close(); + } + } + +} diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyService.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyService.java similarity index 69% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyService.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyService.java index 4c10a2e01..7651a046b 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyService.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyService.java @@ -15,12 +15,12 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static io.streamnative.pulsar.handlers.mqtt.common.Constants.AUTH_MTLS; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; import io.netty.util.concurrent.DefaultThreadFactory; import io.streamnative.pulsar.handlers.mqtt.common.MQTTConnectionManager; -import io.streamnative.pulsar.handlers.mqtt.common.adapter.MQTTProxyAdapter; import io.streamnative.pulsar.handlers.mqtt.common.authentication.MQTTAuthenticationService; import io.streamnative.pulsar.handlers.mqtt.common.event.PulsarEventCenter; import io.streamnative.pulsar.handlers.mqtt.common.event.PulsarEventCenterImpl; @@ -29,6 +29,12 @@ import io.streamnative.pulsar.handlers.mqtt.common.systemtopic.DisabledSystemEventService; import io.streamnative.pulsar.handlers.mqtt.common.systemtopic.SystemEventService; import io.streamnative.pulsar.handlers.mqtt.common.systemtopic.SystemTopicBasedSystemEventService; +import io.streamnative.pulsar.handlers.mqtt.proxy.authentication.mtls.AuthenticationProviderMTls; +import io.streamnative.pulsar.handlers.mqtt.proxy.channel.MQTTProxyAdapter; +import io.streamnative.pulsar.handlers.mqtt.proxy.channel.MQTTProxyChannelInitializer; +import io.streamnative.pulsar.handlers.mqtt.proxy.handler.LookupHandler; +import io.streamnative.pulsar.handlers.mqtt.proxy.handler.PulsarServiceLookupHandler; +import io.streamnative.pulsar.handlers.mqtt.proxy.impl.MQTTProxyException; import java.io.Closeable; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -77,11 +83,20 @@ public MQTTProxyService(BrokerService brokerService, MQTTProxyConfiguration prox configValid(proxyConfig); this.pulsarService = brokerService.getPulsar(); this.proxyConfig = proxyConfig; - this.pskConfiguration = new PSKConfiguration(proxyConfig); + this.pskConfiguration = new PSKConfiguration(proxyConfig.getMqttTlsPskIdentityHint(), + proxyConfig.getMqttTlsPskIdentity(), proxyConfig.getMqttTlsPskIdentityFile(), + proxyConfig.getMqttTlsProtocols(), proxyConfig.getMqttTlsCiphers()); this.authenticationService = proxyConfig.isMqttAuthenticationEnabled() - ? new MQTTAuthenticationService(brokerService, - proxyConfig.getMqttAuthenticationMethods(), - proxyConfig.isMqttProxyMTlsAuthenticationEnabled()) : null; + ? new MQTTAuthenticationService(brokerService, proxyConfig.getMqttAuthenticationMethods()) : null; + if (authenticationService != null && proxyConfig.isMqttProxyMTlsAuthenticationEnabled()) { + AuthenticationProviderMTls providerMTls = new AuthenticationProviderMTls(); + try { + providerMTls.initialize(brokerService.pulsar().getLocalMetadataStore()); + authenticationService.getAuthenticationProviders().put(AUTH_MTLS, providerMTls); + } catch (Exception e) { + log.error("Failed to initialize MQTT authentication method {} ", AUTH_MTLS, e); + } + } this.connectionManager = new MQTTConnectionManager(pulsarService.getAdvertisedAddress()); this.eventService = proxyConfig.isSystemEventEnabled() ? new SystemTopicBasedSystemEventService(pulsarService) @@ -155,6 +170,47 @@ public void start() throws MQTTProxyException { this.eventService.start(); } + public void start0() throws MQTTProxyException { + ServerBootstrap serverBootstrap = new ServerBootstrap(); + serverBootstrap.group(acceptorGroup, workerGroup); + serverBootstrap.channel(EventLoopUtil.getServerSocketChannelClass(workerGroup)); + EventLoopUtil.enableTriggeredMode(serverBootstrap); + + if (proxyConfig.isMqttProxyTlsEnabled() || proxyConfig.isMqttProxyMTlsAuthenticationEnabled()) { + ServerBootstrap tlsBootstrap = serverBootstrap.clone(); + tlsBootstrap.childHandler(new MQTTProxyChannelInitializer( + this, proxyConfig, true, sslContextRefresher)); + try { + listenChannelTls = tlsBootstrap.bind(proxyConfig.getMqttProxyTlsPort()).sync().channel(); + log.info("Started MQTT Proxy with TLS on {}", listenChannelTls.localAddress()); + } catch (InterruptedException e) { + throw new MQTTProxyException(e); + } + } + + if (proxyConfig.isMqttProxyTlsPskEnabled()) { + // init psk config + pskConfiguration.setIdentityHint(proxyConfig.getTlsPskIdentityHint()); + pskConfiguration.setIdentity(proxyConfig.getTlsPskIdentity()); + pskConfiguration.setIdentityFile(proxyConfig.getTlsPskIdentityFile()); + pskConfiguration.setProtocols(proxyConfig.getTlsProtocols()); + pskConfiguration.setCiphers(proxyConfig.getTlsCiphers()); + this.eventService.addListener(pskConfiguration.getEventListener()); + // Add channel initializer + ServerBootstrap tlsPskBootstrap = serverBootstrap.clone(); + tlsPskBootstrap.childHandler(new MQTTProxyChannelInitializer( + this, proxyConfig, false, true, sslContextRefresher)); + try { + listenChannelTlsPsk = tlsPskBootstrap.bind(proxyConfig.getMqttProxyTlsPskPort()).sync().channel(); + log.info("Started MQTT Proxy with TLS-PSK on {}", listenChannelTlsPsk.localAddress()); + } catch (InterruptedException e) { + throw new MQTTProxyException(e); + } + } + this.lookupHandler = new PulsarServiceLookupHandler(pulsarService, proxyConfig); + this.eventService.start(); + } + @Override public void close() { if (listenChannel != null) { diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthRequest.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthRequest.java similarity index 91% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthRequest.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthRequest.java index 998ff8681..2df99cccc 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthRequest.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthRequest.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.common.authentication.mtls; +package io.streamnative.pulsar.handlers.mqtt.proxy.authentication.mtls; import java.util.Map; import lombok.AllArgsConstructor; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthenticationProviderMTls.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthenticationProviderMTls.java similarity index 99% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthenticationProviderMTls.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthenticationProviderMTls.java index dc2efa8d7..1095e3769 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthenticationProviderMTls.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthenticationProviderMTls.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.common.authentication.mtls; +package io.streamnative.pulsar.handlers.mqtt.proxy.authentication.mtls; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/ExpressionCompiler.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/ExpressionCompiler.java similarity index 97% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/ExpressionCompiler.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/ExpressionCompiler.java index 55fdc2f8c..f48460015 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/ExpressionCompiler.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/ExpressionCompiler.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.common.authentication.mtls; +package io.streamnative.pulsar.handlers.mqtt.proxy.authentication.mtls; import dev.cel.common.CelAbstractSyntaxTree; diff --git a/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/package-info.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/package-info.java new file mode 100644 index 000000000..f1195bce7 --- /dev/null +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/package-info.java @@ -0,0 +1,14 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.proxy.authentication.mtls; \ No newline at end of file diff --git a/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/package-info.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/package-info.java new file mode 100644 index 000000000..26c09e6d1 --- /dev/null +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/package-info.java @@ -0,0 +1,14 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.proxy.authentication; \ No newline at end of file diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/AdapterChannel.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/AdapterChannel.java similarity index 95% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/AdapterChannel.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/AdapterChannel.java index ce87ca5fd..54901fb39 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/AdapterChannel.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/AdapterChannel.java @@ -11,11 +11,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.common.adapter; +package io.streamnative.pulsar.handlers.mqtt.proxy.channel; import static com.google.common.base.Preconditions.checkArgument; import io.netty.channel.Channel; import io.streamnative.pulsar.handlers.mqtt.common.Connection; +import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; import io.streamnative.pulsar.handlers.mqtt.common.utils.FutureUtils; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MQTTProxyAdapter.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyAdapter.java similarity index 96% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MQTTProxyAdapter.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyAdapter.java index d0c760542..bc82661a2 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/common/adapter/MQTTProxyAdapter.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyAdapter.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.common.adapter; +package io.streamnative.pulsar.handlers.mqtt.proxy.channel; import static com.google.common.base.Preconditions.checkArgument; import static io.streamnative.pulsar.handlers.mqtt.common.utils.MqttMessageUtils.checkState; @@ -36,10 +36,14 @@ import io.netty.handler.codec.mqtt.MqttUnsubAckMessage; import io.netty.util.concurrent.DefaultThreadFactory; import io.streamnative.pulsar.handlers.mqtt.common.Connection; +import io.streamnative.pulsar.handlers.mqtt.common.adapter.CombineAdapterHandler; +import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterDecoder; +import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterEncoder; +import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; import io.streamnative.pulsar.handlers.mqtt.common.messages.codes.mqtt5.Mqtt5PubReasonCode; import io.streamnative.pulsar.handlers.mqtt.common.utils.MqttUtils; -import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyProtocolMethodProcessor; import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyService; +import io.streamnative.pulsar.handlers.mqtt.proxy.impl.MQTTProxyProtocolMethodProcessor; import java.net.InetSocketAddress; import java.util.Collections; import java.util.List; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyChannelInitializer.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyChannelInitializer.java similarity index 95% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyChannelInitializer.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyChannelInitializer.java index 7617cb2cb..81da2cb73 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyChannelInitializer.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyChannelInitializer.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.proxy; +package io.streamnative.pulsar.handlers.mqtt.proxy.channel; import static org.apache.pulsar.client.impl.PulsarChannelInitializer.TLS_HANDLER; import io.netty.channel.ChannelInitializer; @@ -23,6 +23,9 @@ import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterDecoder; import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterEncoder; import io.streamnative.pulsar.handlers.mqtt.common.psk.PSKUtils; +import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyConfiguration; +import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyService; +import io.streamnative.pulsar.handlers.mqtt.proxy.impl.MQTTProxyException; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import lombok.Getter; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyInboundHandler.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyInboundHandler.java similarity index 85% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyInboundHandler.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyInboundHandler.java index 39ef31f70..ac4eded5e 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyInboundHandler.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/MQTTProxyInboundHandler.java @@ -11,11 +11,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.proxy; +package io.streamnative.pulsar.handlers.mqtt.proxy.channel; import static io.streamnative.pulsar.handlers.mqtt.common.Constants.DEFAULT_CLIENT_ID; import io.netty.channel.ChannelHandlerContext; import io.streamnative.pulsar.handlers.mqtt.common.MQTTCommonInboundHandler; +import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyService; +import io.streamnative.pulsar.handlers.mqtt.proxy.impl.MQTTProxyProtocolMethodProcessor; import lombok.extern.slf4j.Slf4j; /** diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/package-info.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/package-info.java similarity index 90% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/package-info.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/package-info.java index e26b2fc58..8dcf893ad 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/metric/package-info.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/channel/package-info.java @@ -15,4 +15,4 @@ /** * Package info. */ -package io.streamnative.pulsar.handlers.mqtt.broker.metric; +package io.streamnative.pulsar.handlers.mqtt.proxy.channel; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/LookupHandler.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/LookupHandler.java similarity index 94% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/LookupHandler.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/LookupHandler.java index 64ad3de8a..17120fa30 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/LookupHandler.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/LookupHandler.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.proxy; +package io.streamnative.pulsar.handlers.mqtt.proxy.handler; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/PulsarServiceLookupHandler.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/PulsarServiceLookupHandler.java similarity index 98% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/PulsarServiceLookupHandler.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/PulsarServiceLookupHandler.java index 9ead09ef4..7d0497f49 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/PulsarServiceLookupHandler.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/PulsarServiceLookupHandler.java @@ -11,10 +11,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.proxy; +package io.streamnative.pulsar.handlers.mqtt.proxy.handler; import static org.apache.commons.lang3.StringUtils.isNotBlank; import io.streamnative.pulsar.handlers.mqtt.common.utils.ConfigurationUtils; +import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyConfiguration; import java.net.InetSocketAddress; import java.util.Arrays; import java.util.Collections; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/package-info.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/package-info.java similarity index 90% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/package-info.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/package-info.java index b3aef915b..77a8cd595 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/codec/package-info.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/handler/package-info.java @@ -15,4 +15,4 @@ /** * Package info. */ -package io.streamnative.pulsar.handlers.mqtt.broker.codec; +package io.streamnative.pulsar.handlers.mqtt.proxy.handler; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyException.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MQTTProxyException.java similarity index 93% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyException.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MQTTProxyException.java index b72ecaca9..94927ed41 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyException.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MQTTProxyException.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.proxy; +package io.streamnative.pulsar.handlers.mqtt.proxy.impl; /** * Proxy exception. diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyProtocolMethodProcessor.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MQTTProxyProtocolMethodProcessor.java similarity index 98% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyProtocolMethodProcessor.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MQTTProxyProtocolMethodProcessor.java index 481a82e9a..9d495418e 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MQTTProxyProtocolMethodProcessor.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MQTTProxyProtocolMethodProcessor.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.proxy; +package io.streamnative.pulsar.handlers.mqtt.proxy.impl; import static io.streamnative.pulsar.handlers.mqtt.common.utils.MqttMessageUtils.createMqtt5ConnectMessage; import static io.streamnative.pulsar.handlers.mqtt.common.utils.MqttMessageUtils.createMqttPublishMessage; @@ -30,8 +30,6 @@ import io.streamnative.pulsar.handlers.mqtt.common.Connection; import io.streamnative.pulsar.handlers.mqtt.common.MQTTConnectionManager; import io.streamnative.pulsar.handlers.mqtt.common.TopicFilter; -import io.streamnative.pulsar.handlers.mqtt.common.adapter.AdapterChannel; -import io.streamnative.pulsar.handlers.mqtt.common.adapter.MQTTProxyAdapter; import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; import io.streamnative.pulsar.handlers.mqtt.common.event.AutoSubscribeHandler; import io.streamnative.pulsar.handlers.mqtt.common.messages.ack.MqttAck; @@ -47,6 +45,11 @@ import io.streamnative.pulsar.handlers.mqtt.common.utils.MqttUtils; import io.streamnative.pulsar.handlers.mqtt.common.utils.NettyUtils; import io.streamnative.pulsar.handlers.mqtt.common.utils.PulsarTopicUtils; +import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyConfiguration; +import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyService; +import io.streamnative.pulsar.handlers.mqtt.proxy.channel.AdapterChannel; +import io.streamnative.pulsar.handlers.mqtt.proxy.channel.MQTTProxyAdapter; +import io.streamnative.pulsar.handlers.mqtt.proxy.handler.LookupHandler; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Collections; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MessageAckTracker.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MessageAckTracker.java similarity index 96% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MessageAckTracker.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MessageAckTracker.java index d716d2c0a..71acf8426 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/MessageAckTracker.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MessageAckTracker.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.proxy; +package io.streamnative.pulsar.handlers.mqtt.proxy.impl; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/package-info.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/package-info.java similarity index 91% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/package-info.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/package-info.java index 6ac7f8452..d135c9b2d 100644 --- a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/broker/rest/package-info.java +++ b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/package-info.java @@ -15,4 +15,4 @@ /** * Package info. */ -package io.streamnative.pulsar.handlers.mqtt.broker.rest; +package io.streamnative.pulsar.handlers.mqtt.proxy.impl; diff --git a/mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/package-info.java b/mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/package-info.java similarity index 100% rename from mqtt-impl/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/package-info.java rename to mqtt-proxy/src/main/java/io/streamnative/pulsar/handlers/mqtt/proxy/package-info.java diff --git a/mqtt-proxy/src/main/resources/META-INF/services/pulsar-protocol-handler.yml b/mqtt-proxy/src/main/resources/META-INF/services/pulsar-protocol-handler.yml new file mode 100644 index 000000000..1b3bc09fa --- /dev/null +++ b/mqtt-proxy/src/main/resources/META-INF/services/pulsar-protocol-handler.yml @@ -0,0 +1,17 @@ +# +# Licensed 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. +# + +name: mqtt-proxy +description: MQTT Proxy Protocol Handler +handlerClass: io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyProtocolHandler diff --git a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthenticationProviderMTlsTest.java b/mqtt-proxy/src/test/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthenticationProviderMTlsTest.java similarity index 99% rename from mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthenticationProviderMTlsTest.java rename to mqtt-proxy/src/test/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthenticationProviderMTlsTest.java index 8b7030624..7102847d0 100644 --- a/mqtt-impl/src/test/java/io/streamnative/pulsar/handlers/mqtt/common/authentication/mtls/AuthenticationProviderMTlsTest.java +++ b/mqtt-proxy/src/test/java/io/streamnative/pulsar/handlers/mqtt/proxy/authentication/mtls/AuthenticationProviderMTlsTest.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.streamnative.pulsar.handlers.mqtt.common.authentication.mtls; +package io.streamnative.pulsar.handlers.mqtt.proxy.authentication.mtls; import com.fasterxml.jackson.databind.ObjectMapper; import io.netty.channel.local.LocalAddress; diff --git a/mqtt-proxy/src/test/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MessageAckTrackerTest.java b/mqtt-proxy/src/test/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MessageAckTrackerTest.java new file mode 100644 index 000000000..49a2dedbb --- /dev/null +++ b/mqtt-proxy/src/test/java/io/streamnative/pulsar/handlers/mqtt/proxy/impl/MessageAckTrackerTest.java @@ -0,0 +1,33 @@ +/** + * Licensed 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 io.streamnative.pulsar.handlers.mqtt.proxy.impl; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; + +public class MessageAckTrackerTest { + + @Test + public void testTracker() { + MessageAckTracker messageAckTracker = new MessageAckTracker(); + final int messageId = 11111; + messageAckTracker.increment(messageId); + messageAckTracker.increment(messageId); + assertFalse(messageAckTracker.checkIfSendAck(messageId)); + assertTrue(messageAckTracker.checkIfSendAck(messageId)); + final int unknownMessageId = 123; + assertFalse(messageAckTracker.checkIfSendAck(unknownMessageId)); + } +} diff --git a/mqtt-proxy/src/test/resources/mqtt-test.conf b/mqtt-proxy/src/test/resources/mqtt-test.conf new file mode 100644 index 000000000..64c4e6813 --- /dev/null +++ b/mqtt-proxy/src/test/resources/mqtt-test.conf @@ -0,0 +1,985 @@ +# +# Licensed 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. +# + +### --- General broker settings --- ### + +# Zookeeper quorum connection string +zookeeperServers= + +# Configuration Store connection string +configurationStoreServers= + +brokerServicePort=6650 + +# Port to use to server HTTP request +webServicePort=8080 + +# Hostname or IP address the service binds on, default is 0.0.0.0. +bindAddress=0.0.0.0 + +# Hostname or IP address the service advertises to the outside world. If not set, the value of InetAddress.getLocalHost().getHostName() is used. +advertisedAddress= + +# Enable or disable the HAProxy protocol. +haProxyProtocolEnabled=false + +# Number of threads to use for Netty IO. Default is set to 2 * Runtime.getRuntime().availableProcessors() +numIOThreads= + +# Number of threads to use for ordered executor. The ordered executor is used to operate with zookeeper, +# such as init zookeeper client, get namespace policies from zookeeper etc. It also used to split bundle. Default is 8 +numOrderedExecutorThreads=8 + +# Number of threads to use for HTTP requests processing. Default is set to 2 * Runtime.getRuntime().availableProcessors() +numHttpServerThreads= + +messagingProtocols=mqtt +protocolHandlerDirectory=./protocols +mqttListeners=mqtt://127.0.0.1:1883 +advertisedAddress=127.0.0.1 + +# Number of thread pool size to use for pulsar broker service. +# The executor in thread pool will do basic broker operation like load/unload bundle, update managedLedgerConfig, +# update topic/subscription/replicator message dispatch rate, do leader election etc. +# Default is Runtime.getRuntime().availableProcessors() +numExecutorThreadPoolSize= + +# Number of thread pool size to use for pulsar zookeeper callback service +# The cache executor thread pool is used for restarting global zookeeper session. +# Default is 10 +numCacheExecutorThreadPoolSize=10 + +# Max concurrent web requests +maxConcurrentHttpRequests=1024 + +# Name of the cluster to which this broker belongs to +clusterName=standalone + +# Enable cluster's failure-domain which can distribute brokers into logical region +failureDomainsEnabled=false + +# Zookeeper session timeout in milliseconds +zooKeeperSessionTimeoutMillis=30000 + +# ZooKeeper operation timeout in seconds +zooKeeperOperationTimeoutSeconds=30 + +# ZooKeeper cache expiry time in seconds +zooKeeperCacheExpirySeconds=300 + +# Time to wait for broker graceful shutdown. After this time elapses, the process will be killed +brokerShutdownTimeoutMs=60000 + +# Flag to skip broker shutdown when broker handles Out of memory error +skipBrokerShutdownOnOOM=false + +# Enable backlog quota check. Enforces action on topic when the quota is reached +backlogQuotaCheckEnabled=true + +# How often to check for topics that have reached the quota +backlogQuotaCheckIntervalInSeconds=60 + +# Default per-topic backlog quota limit +backlogQuotaDefaultLimitGB=10 + +# Default per-topic backlog quota time limit in second, less than 0 means no limitation. default is -1. +backlogQuotaDefaultLimitSecond=-1 + +# Default ttl for namespaces if ttl is not already configured at namespace policies. (disable default-ttl with value 0) +ttlDurationDefaultInSeconds=0 + +# Enable the deletion of inactive topics +brokerDeleteInactiveTopicsEnabled=true + +# How often to check for inactive topics +brokerDeleteInactiveTopicsFrequencySeconds=60 + +# Max pending publish requests per connection to avoid keeping large number of pending +# requests in memory. Default: 1000 +maxPendingPublishRequestsPerConnection=1000 + +# How frequently to proactively check and purge expired messages +messageExpiryCheckIntervalInMinutes=5 + +# How long to delay rewinding cursor and dispatching messages when active consumer is changed +activeConsumerFailoverDelayTimeMillis=1000 + +# How long to delete inactive subscriptions from last consuming +# When it is 0, inactive subscriptions are not deleted automatically +subscriptionExpirationTimeMinutes=0 + +# Enable subscription message redelivery tracker to send redelivery count to consumer (default is enabled) +subscriptionRedeliveryTrackerEnabled=true + +# On KeyShared subscriptions, with default AUTO_SPLIT mode, use splitting ranges or +# consistent hashing to reassign keys to new consumers +subscriptionKeySharedUseConsistentHashing=false + +# On KeyShared subscriptions, number of points in the consistent-hashing ring. +# The higher the number, the more equal the assignment of keys to consumers +subscriptionKeySharedConsistentHashingReplicaPoints=100 + +# How frequently to proactively check and purge expired subscription +subscriptionExpiryCheckIntervalInMinutes=5 + +# Set the default behavior for message deduplication in the broker +# This can be overridden per-namespace. If enabled, broker will reject +# messages that were already stored in the topic +brokerDeduplicationEnabled=false + +# Maximum number of producer information that it's going to be +# persisted for deduplication purposes +brokerDeduplicationMaxNumberOfProducers=10000 + +# Number of entries after which a dedup info snapshot is taken. +# A bigger interval will lead to less snapshots being taken though it would +# increase the topic recovery time, when the entries published after the +# snapshot need to be replayed +brokerDeduplicationEntriesInterval=1000 + +# Time of inactivity after which the broker will discard the deduplication information +# relative to a disconnected producer. Default is 6 hours. +brokerDeduplicationProducerInactivityTimeoutMinutes=360 + +# When a namespace is created without specifying the number of bundle, this +# value will be used as the default +defaultNumberOfNamespaceBundles=4 + +# Max number of topics allowed to be created in the namespace. When the topics reach the max topics of the namespace, +# the broker should reject the new topic request(include topic auto-created by the producer or consumer) +# until the number of connected consumers decrease. +# Using a value of 0, is disabling maxTopicsPerNamespace-limit check. +maxTopicsPerNamespace=0 + +# Enable check for minimum allowed client library version +clientLibraryVersionCheckEnabled=false + +# Path for the file used to determine the rotation status for the broker when responding +# to service discovery health checks +statusFilePath=/usr/local/apache/htdocs + +# Max number of unacknowledged messages allowed to receive messages by a consumer on a shared subscription. Broker will stop sending +# messages to consumer once, this limit reaches until consumer starts acknowledging messages back +# Using a value of 0, is disabling unackeMessage limit check and consumer can receive messages without any restriction +maxUnackedMessagesPerConsumer=50000 + +# Max number of unacknowledged messages allowed per shared subscription. Broker will stop dispatching messages to +# all consumers of the subscription once this limit reaches until consumer starts acknowledging messages back and +# unack count reaches to limit/2. Using a value of 0, is disabling unackedMessage-limit +# check and dispatcher can dispatch messages without any restriction +maxUnackedMessagesPerSubscription=200000 + +# Max number of unacknowledged messages allowed per broker. Once this limit reaches, broker will stop dispatching +# messages to all shared subscription which has higher number of unack messages until subscriptions start +# acknowledging messages back and unack count reaches to limit/2. Using a value of 0, is disabling +# unackedMessage-limit check and broker doesn't block dispatchers +maxUnackedMessagesPerBroker=0 + +# Once broker reaches maxUnackedMessagesPerBroker limit, it blocks subscriptions which has higher unacked messages +# than this percentage limit and subscription will not receive any new messages until that subscription acks back +# limit/2 messages +maxUnackedMessagesPerSubscriptionOnBrokerBlocked=0.16 + +# Tick time to schedule task that checks topic publish rate limiting across all topics +# Reducing to lower value can give more accuracy while throttling publish but +# it uses more CPU to perform frequent check. (Disable publish throttling with value 0) +topicPublisherThrottlingTickTimeMillis=2 + +# Enable precise rate limit for topic publish +preciseTopicPublishRateLimiterEnable=false + +# Tick time to schedule task that checks broker publish rate limiting across all topics +# Reducing to lower value can give more accuracy while throttling publish but +# it uses more CPU to perform frequent check. (Disable publish throttling with value 0) +brokerPublisherThrottlingTickTimeMillis=50 + +# Max Rate(in 1 seconds) of Message allowed to publish for a broker if broker publish rate limiting enabled +# (Disable message rate limit with value 0) +brokerPublisherThrottlingMaxMessageRate=0 + +# Max Rate(in 1 seconds) of Byte allowed to publish for a broker if broker publish rate limiting enabled +# (Disable byte rate limit with value 0) +brokerPublisherThrottlingMaxByteRate=0 + +# Default messages per second dispatch throttling-limit for every topic. Using a value of 0, is disabling default +# message dispatch-throttling +dispatchThrottlingRatePerTopicInMsg=0 + +# Default bytes per second dispatch throttling-limit for every topic. Using a value of 0, is disabling +# default message-byte dispatch-throttling +dispatchThrottlingRatePerTopicInByte=0 + +# Dispatch rate-limiting relative to publish rate. +# (Enabling flag will make broker to dynamically update dispatch-rate relatively to publish-rate: +# throttle-dispatch-rate = (publish-rate + configured dispatch-rate). +dispatchThrottlingRateRelativeToPublishRate=false + +# By default we enable dispatch-throttling for both caught up consumers as well as consumers who have +# backlog. +dispatchThrottlingOnNonBacklogConsumerEnabled=true + +# Precise dispathcer flow control according to history message number of each entry +preciseDispatcherFlowControl=false + +# Max number of concurrent lookup request broker allows to throttle heavy incoming lookup traffic +maxConcurrentLookupRequest=50000 + +# Max number of concurrent topic loading request broker allows to control number of zk-operations +maxConcurrentTopicLoadRequest=5000 + +# Max concurrent non-persistent message can be processed per connection +maxConcurrentNonPersistentMessagePerConnection=1000 + +# Number of worker threads to serve non-persistent topic +numWorkerThreadsForNonPersistentTopic=8 + +# Enable broker to load persistent topics +enablePersistentTopics=true + +# Enable broker to load non-persistent topics +enableNonPersistentTopics=true + +# Max number of producers allowed to connect to topic. Once this limit reaches, Broker will reject new producers +# until the number of connected producers decrease. +# Using a value of 0, is disabling maxProducersPerTopic-limit check. +maxProducersPerTopic=0 + +# Max number of producers with the same IP address allowed to connect to topic. +# Once this limit reaches, Broker will reject new producers until the number of +# connected producers with the same IP address decrease. +# Using a value of 0, is disabling maxSameAddressProducersPerTopic-limit check. +maxSameAddressProducersPerTopic=0 + +# Enforce producer to publish encrypted messages.(default disable). +encryptionRequireOnProducer=false + +# Max number of consumers allowed to connect to topic. Once this limit reaches, Broker will reject new consumers +# until the number of connected consumers decrease. +# Using a value of 0, is disabling maxConsumersPerTopic-limit check. +maxConsumersPerTopic=0 + +# Max number of consumers with the same IP address allowed to connect to topic. +# Once this limit reaches, Broker will reject new consumers until the number of +# connected consumers with the same IP address decrease. +# Using a value of 0, is disabling maxSameAddressConsumersPerTopic-limit check. +maxSameAddressConsumersPerTopic=0 + +# Max number of subscriptions allowed to subscribe to topic. Once this limit reaches, broker will reject +# new subscription until the number of subscribed subscriptions decrease. +# Using a value of 0, is disabling maxSubscriptionsPerTopic limit check. +maxSubscriptionsPerTopic=0 + +# Max number of consumers allowed to connect to subscription. Once this limit reaches, Broker will reject new consumers +# until the number of connected consumers decrease. +# Using a value of 0, is disabling maxConsumersPerSubscription-limit check. +maxConsumersPerSubscription=0 + +# Max number of partitions per partitioned topic +# Use 0 or negative number to disable the check +maxNumPartitionsPerPartitionedTopic=0 + +### --- TLS --- ### +# Deprecated - Use webServicePortTls and brokerServicePortTls instead +tlsEnabled=false + +# Tls cert refresh duration in seconds (set 0 to check on every new connection) +tlsCertRefreshCheckDurationSec=300 + +# Path for the TLS certificate file +tlsCertificateFilePath= + +# Path for the TLS private key file +tlsKeyFilePath= + +# Path for the trusted TLS certificate file. +# This cert is used to verify that any certs presented by connecting clients +# are signed by a certificate authority. If this verification +# fails, then the certs are untrusted and the connections are dropped. +tlsTrustCertsFilePath= + +# Accept untrusted TLS certificate from client. +# If true, a client with a cert which cannot be verified with the +# 'tlsTrustCertsFilePath' cert will allowed to connect to the server, +# though the cert will not be used for client authentication. +tlsAllowInsecureConnection=false + +# Specify the tls protocols the broker will use to negotiate during TLS handshake +# (a comma-separated list of protocol names). +# Examples:- [TLSv1.3, TLSv1.2] +tlsProtocols= + +# Specify the tls cipher the broker will use to negotiate during TLS Handshake +# (a comma-separated list of ciphers). +# Examples:- [TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256] +tlsCiphers= + +# Trusted client certificates are required for to connect TLS +# Reject the Connection if the Client Certificate is not trusted. +# In effect, this requires that all connecting clients perform TLS client +# authentication. +tlsRequireTrustedClientCertOnConnect=false + +### --- KeyStore TLS config variables --- ### +# Enable TLS with KeyStore type configuration in broker. +tlsEnabledWithKeyStore=false + +# TLS Provider for KeyStore type +tlsProvider= + +# TLS KeyStore type configuration in broker: JKS, PKCS12 +tlsKeyStoreType=JKS + +# TLS KeyStore path in broker +tlsKeyStore= + +# TLS KeyStore password for broker +tlsKeyStorePassword= + +# TLS TrustStore type configuration in broker: JKS, PKCS12 +tlsTrustStoreType=JKS + +# TLS TrustStore path in broker +tlsTrustStore= + +# TLS TrustStore password for broker +tlsTrustStorePassword= + +# Whether internal client use KeyStore type to authenticate with Pulsar brokers +brokerClientTlsEnabledWithKeyStore=false + +# The TLS Provider used by internal client to authenticate with other Pulsar brokers +brokerClientSslProvider= + +# TLS TrustStore type configuration for internal client: JKS, PKCS12 +# used by the internal client to authenticate with Pulsar brokers +brokerClientTlsTrustStoreType=JKS + +# TLS TrustStore path for internal client +# used by the internal client to authenticate with Pulsar brokers +brokerClientTlsTrustStore= + +# TLS TrustStore password for internal client, +# used by the internal client to authenticate with Pulsar brokers +brokerClientTlsTrustStorePassword= + +# Specify the tls cipher the internal client will use to negotiate during TLS Handshake +# (a comma-separated list of ciphers) +# e.g. [TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256]. +# used by the internal client to authenticate with Pulsar brokers +brokerClientTlsCiphers= + +# Specify the tls protocols the broker will use to negotiate during TLS handshake +# (a comma-separated list of protocol names). +# e.g. [TLSv1.3, TLSv1.2] +# used by the internal client to authenticate with Pulsar brokers +brokerClientTlsProtocols= + +# Enable or disable system topic +systemTopicEnabled=false + +# Enable or disable topic level policies, topic level policies depends on the system topic +# Please enable the system topic first. +topicLevelPoliciesEnabled=false + +# If a topic remains fenced for this number of seconds, it will be closed forcefully. +# If it is set to 0 or a negative number, the fenced topic will not be closed. +topicFencingTimeoutSeconds=0 + +### --- Authentication --- ### +# Role names that are treated as "proxy roles". If the broker sees a request with +#role as proxyRoles - it will demand to see a valid original principal. +proxyRoles= + +# If this flag is set then the broker authenticates the original Auth data +# else it just accepts the originalPrincipal and authorizes it (if required). +authenticateOriginalAuthData=false + +# Enable authentication +authenticationEnabled=false + +# Authentication provider name list, which is comma separated list of class names +authenticationProviders= + +# Enforce authorization +authorizationEnabled=false + +# Authorization provider fully qualified class-name +authorizationProvider=org.apache.pulsar.broker.authorization.PulsarAuthorizationProvider + +# Allow wildcard matching in authorization +# (wildcard matching only applicable if wildcard-char: +# * presents at first or last position eg: *.pulsar.service, pulsar.service.*) +authorizationAllowWildcardsMatching=false + +# Role names that are treated as "super-user", meaning they will be able to do all admin +# operations and publish/consume from all topics +superUserRoles= + +# Authentication settings of the broker itself. Used when the broker connects to other brokers, +# either in same or other clusters +brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationBasic +brokerClientAuthenticationParameters={"userId":"superUser","password":"supepass"} + +# Supported Athenz provider domain names(comma separated) for authentication +athenzDomainNames= + +# When this parameter is not empty, unauthenticated users perform as anonymousUserRole +anonymousUserRole= + + +### --- Token Authentication Provider --- ### + +## Symmetric key +# Configure the secret key to be used to validate auth tokens +# The key can be specified like: +# tokenSecretKey=data:;base64,xxxxxxxxx +# tokenSecretKey=file:///my/secret.key ( Note: key file must be DER-encoded ) +tokenSecretKey= + +## Asymmetric public/private key pair +# Configure the public key to be used to validate auth tokens +# The key can be specified like: +# tokenPublicKey=data:;base64,xxxxxxxxx +# tokenPublicKey=file:///my/public.key ( Note: key file must be DER-encoded ) +tokenPublicKey= + + +# The token "claim" that will be interpreted as the authentication "role" or "principal" by AuthenticationProviderToken (defaults to "sub" if blank) +tokenAuthClaim= + +# The token audience "claim" name, e.g. "aud", that will be used to get the audience from token. +# If not set, audience will not be verified. +tokenAudienceClaim= + +# The token audience stands for this broker. The field `tokenAudienceClaim` of a valid token, need contains this. +tokenAudience= + +### --- BookKeeper Client --- ### + +# Authentication plugin to use when connecting to bookies +bookkeeperClientAuthenticationPlugin= + +# BookKeeper auth plugin implementatation specifics parameters name and values +bookkeeperClientAuthenticationParametersName= +bookkeeperClientAuthenticationParameters= + +# Timeout for BK add / read operations +bookkeeperClientTimeoutInSeconds=30 + +# Number of BookKeeper client worker threads +# Default is Runtime.getRuntime().availableProcessors() +bookkeeperClientNumWorkerThreads= + +# Speculative reads are initiated if a read request doesn't complete within a certain time +# Using a value of 0, is disabling the speculative reads +bookkeeperClientSpeculativeReadTimeoutInMillis=0 + +# Number of channels per bookie +bookkeeperNumberOfChannelsPerBookie=16 + +# Enable bookies health check. Bookies that have more than the configured number of failure within +# the interval will be quarantined for some time. During this period, new ledgers won't be created +# on these bookies +bookkeeperClientHealthCheckEnabled=true +bookkeeperClientHealthCheckIntervalSeconds=60 +bookkeeperClientHealthCheckErrorThresholdPerInterval=5 +bookkeeperClientHealthCheckQuarantineTimeInSeconds=1800 + +#bookie quarantine ratio to avoid all clients quarantine the high pressure bookie servers at the same time +bookkeeperClientQuarantineRatio=1.0 + +# Enable rack-aware bookie selection policy. BK will chose bookies from different racks when +# forming a new bookie ensemble +# This parameter related to ensemblePlacementPolicy in conf/bookkeeper.conf, if enabled, ensemblePlacementPolicy +# should be set to org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy +bookkeeperClientRackawarePolicyEnabled=true + +# Enable region-aware bookie selection policy. BK will chose bookies from +# different regions and racks when forming a new bookie ensemble. +# If enabled, the value of bookkeeperClientRackawarePolicyEnabled is ignored +# This parameter related to ensemblePlacementPolicy in conf/bookkeeper.conf, if enabled, ensemblePlacementPolicy +# should be set to org.apache.bookkeeper.client.RegionAwareEnsemblePlacementPolicy +bookkeeperClientRegionawarePolicyEnabled=false + +# Minimum number of racks per write quorum. BK rack-aware bookie selection policy will try to +# get bookies from at least 'bookkeeperClientMinNumRacksPerWriteQuorum' racks for a write quorum. +bookkeeperClientMinNumRacksPerWriteQuorum=1 + +# Enforces rack-aware bookie selection policy to pick bookies from 'bookkeeperClientMinNumRacksPerWriteQuorum' +# racks for a writeQuorum. +# If BK can't find bookie then it would throw BKNotEnoughBookiesException instead of picking random one. +bookkeeperClientEnforceMinNumRacksPerWriteQuorum=false + +# Enable/disable reordering read sequence on reading entries. +bookkeeperClientReorderReadSequenceEnabled=false + +# Enable bookie isolation by specifying a list of bookie groups to choose from. Any bookie +# outside the specified groups will not be used by the broker +bookkeeperClientIsolationGroups= + +# Enable bookie secondary-isolation group if bookkeeperClientIsolationGroups doesn't +# have enough bookie available. +bookkeeperClientSecondaryIsolationGroups= + +# Minimum bookies that should be available as part of bookkeeperClientIsolationGroups +# else broker will include bookkeeperClientSecondaryIsolationGroups bookies in isolated list. +bookkeeperClientMinAvailableBookiesInIsolationGroups= + +# Set the client security provider factory class name. +# Default: org.apache.bookkeeper.tls.TLSContextFactory +bookkeeperTLSProviderFactoryClass=org.apache.bookkeeper.tls.TLSContextFactory + +# Enable tls authentication with bookie +bookkeeperTLSClientAuthentication=false + +# Supported type: PEM, JKS, PKCS12. Default value: PEM +bookkeeperTLSKeyFileType=PEM + +#Supported type: PEM, JKS, PKCS12. Default value: PEM +bookkeeperTLSTrustCertTypes=PEM + +# Path to file containing keystore password, if the client keystore is password protected. +bookkeeperTLSKeyStorePasswordPath= + +# Path to file containing truststore password, if the client truststore is password protected. +bookkeeperTLSTrustStorePasswordPath= + +# Path for the TLS private key file +bookkeeperTLSKeyFilePath= + +# Path for the TLS certificate file +bookkeeperTLSCertificateFilePath= + +# Path for the trusted TLS certificate file +bookkeeperTLSTrustCertsFilePath= + +# Enable/disable disk weight based placement. Default is false +bookkeeperDiskWeightBasedPlacementEnabled=false + +# Set the interval to check the need for sending an explicit LAC +# A value of '0' disables sending any explicit LACs. Default is 0. +bookkeeperExplicitLacIntervalInMills=0 + +# Use older Bookkeeper wire protocol with bookie +bookkeeperUseV2WireProtocol=true + +# Expose bookkeeper client managed ledger stats to prometheus. default is false +# bookkeeperClientExposeStatsToPrometheus=false + +### --- Managed Ledger --- ### + +# Number of bookies to use when creating a ledger +managedLedgerDefaultEnsembleSize=1 + +# Number of copies to store for each message +managedLedgerDefaultWriteQuorum=1 + +# Number of guaranteed copies (acks to wait before write is complete) +managedLedgerDefaultAckQuorum=1 + +# How frequently to flush the cursor positions that were accumulated due to rate limiting. (seconds). +# Default is 60 seconds +managedLedgerCursorPositionFlushSeconds = 60 + +# Default type of checksum to use when writing to BookKeeper. Default is "CRC32C" +# Other possible options are "CRC32", "MAC" or "DUMMY" (no checksum). +managedLedgerDigestType=CRC32C + +# Number of threads to be used for managed ledger tasks dispatching +managedLedgerNumWorkerThreads=4 + +# Number of threads to be used for managed ledger scheduled tasks +managedLedgerNumSchedulerThreads=4 + +# Amount of memory to use for caching data payload in managed ledger. This memory +# is allocated from JVM direct memory and it's shared across all the topics +# running in the same broker. By default, uses 1/5th of available direct memory +managedLedgerCacheSizeMB= + +# Whether we should make a copy of the entry payloads when inserting in cache +managedLedgerCacheCopyEntries=false + +# Threshold to which bring down the cache level when eviction is triggered +managedLedgerCacheEvictionWatermark=0.9 + +# Configure the cache eviction frequency for the managed ledger cache (evictions/sec) +managedLedgerCacheEvictionFrequency=100.0 + +# All entries that have stayed in cache for more than the configured time, will be evicted +managedLedgerCacheEvictionTimeThresholdMillis=1000 + +# Configure the threshold (in number of entries) from where a cursor should be considered 'backlogged' +# and thus should be set as inactive. +managedLedgerCursorBackloggedThreshold=1000 + +# Rate limit the amount of writes generated by consumer acking the messages +managedLedgerDefaultMarkDeleteRateLimit=0.1 + +# Max number of entries to append to a ledger before triggering a rollover +# A ledger rollover is triggered after the min rollover time has passed +# and one of the following conditions is true: +# * The max rollover time has been reached +# * The max entries have been written to the ledger +# * The max ledger size has been written to the ledger +managedLedgerMaxEntriesPerLedger=50000 + +# Minimum time between ledger rollover for a topic +managedLedgerMinLedgerRolloverTimeMinutes=10 + +# Maximum time before forcing a ledger rollover for a topic +managedLedgerMaxLedgerRolloverTimeMinutes=240 + +# Max number of entries to append to a cursor ledger +managedLedgerCursorMaxEntriesPerLedger=50000 + +# Max time before triggering a rollover on a cursor ledger +managedLedgerCursorRolloverTimeInSeconds=14400 + +# Maximum ledger size before triggering a rollover for a topic (MB) +managedLedgerMaxSizePerLedgerMbytes=2048 + +# Max number of "acknowledgment holes" that are going to be persistently stored. +# When acknowledging out of order, a consumer will leave holes that are supposed +# to be quickly filled by acking all the messages. The information of which +# messages are acknowledged is persisted by compressing in "ranges" of messages +# that were acknowledged. After the max number of ranges is reached, the information +# will only be tracked in memory and messages will be redelivered in case of +# crashes. +managedLedgerMaxUnackedRangesToPersist=10000 + +# Max number of "acknowledgment holes" that can be stored in Zookeeper. If number of unack message range is higher +# than this limit then broker will persist unacked ranges into bookkeeper to avoid additional data overhead into +# zookeeper. +managedLedgerMaxUnackedRangesToPersistInZooKeeper=1000 + +# Skip reading non-recoverable/unreadable data-ledger under managed-ledger's list. It helps when data-ledgers gets +# corrupted at bookkeeper and managed-cursor is stuck at that ledger. +autoSkipNonRecoverableData=false + +# operation timeout while updating managed-ledger metadata. +managedLedgerMetadataOperationsTimeoutSeconds=60 + +# Read entries timeout when broker tries to read messages from bookkeeper. +managedLedgerReadEntryTimeoutSeconds=0 + +# Add entry timeout when broker tries to publish message to bookkeeper (0 to disable it). +managedLedgerAddEntryTimeoutSeconds=0 + +# New entries check delay for the cursor under the managed ledger. +# If no new messages in the topic, the cursor will try to check again after the delay time. +# For consumption latency sensitive scenario, can set to a smaller value or set to 0. +# Of course, use a smaller value may degrade consumption throughput. Default is 10ms. +managedLedgerNewEntriesCheckDelayInMillis=10 + +# Use Open Range-Set to cache unacked messages +managedLedgerUnackedRangesOpenCacheSetEnabled=true + +# Managed ledger prometheus stats latency rollover seconds (default: 60s) +managedLedgerPrometheusStatsLatencyRolloverSeconds=60 + +# Whether trace managed ledger task execution time +managedLedgerTraceTaskExecution=true + +# If you want to custom bookie ID or use a dynamic network address for the bookie, +# you can set this option. +# Bookie advertises itself using bookieId rather than +# BookieSocketAddress (hostname:port or IP:port). +# bookieId is a non empty string that can contain ASCII digits and letters ([a-zA-Z9-0]), +# colons, dashes, and dots. +# For more information about bookieId, see http://bookkeeper.apache.org/bps/BP-41-bookieid/. +# bookieId= + +### --- Load balancer --- ### + +loadManagerClassName=org.apache.pulsar.broker.loadbalance.NoopLoadManager + +# Enable load balancer +loadBalancerEnabled=false + +# Percentage of change to trigger load report update +loadBalancerReportUpdateThresholdPercentage=10 + +# maximum interval to update load report +loadBalancerReportUpdateMaxIntervalMinutes=15 + +# Frequency of report to collect +loadBalancerHostUsageCheckIntervalMinutes=1 + +# Load shedding interval. Broker periodically checks whether some traffic should be offload from +# some over-loaded broker to other under-loaded brokers +loadBalancerSheddingIntervalMinutes=1 + +# Prevent the same topics to be shed and moved to other broker more that once within this timeframe +loadBalancerSheddingGracePeriodMinutes=30 + +# Usage threshold to allocate max number of topics to broker +loadBalancerBrokerMaxTopics=50000 + +# Interval to flush dynamic resource quota to ZooKeeper +loadBalancerResourceQuotaUpdateIntervalMinutes=15 + +# enable/disable namespace bundle auto split +loadBalancerAutoBundleSplitEnabled=true + +# enable/disable automatic unloading of split bundles +loadBalancerAutoUnloadSplitBundlesEnabled=true + +# maximum topics in a bundle, otherwise bundle split will be triggered +loadBalancerNamespaceBundleMaxTopics=1000 + +# maximum sessions (producers + consumers) in a bundle, otherwise bundle split will be triggered +loadBalancerNamespaceBundleMaxSessions=1000 + +# maximum msgRate (in + out) in a bundle, otherwise bundle split will be triggered +loadBalancerNamespaceBundleMaxMsgRate=30000 + +# maximum bandwidth (in + out) in a bundle, otherwise bundle split will be triggered +loadBalancerNamespaceBundleMaxBandwidthMbytes=100 + +# maximum number of bundles in a namespace +loadBalancerNamespaceMaximumBundles=128 + +# The broker resource usage threshold. +# When the broker resource usage is greater than the pulsar cluster average resource usage, +# the threshold shedder will be triggered to offload bundles from the broker. +# It only takes effect in the ThresholdShedder strategy. +loadBalancerBrokerThresholdShedderPercentage=10 + +# When calculating new resource usage, the history usage accounts for. +# It only takes effect in the ThresholdShedder strategy. +loadBalancerHistoryResourcePercentage=0.9 + +# The BandWithIn usage weight when calculating new resource usage. +# It only takes effect in the ThresholdShedder strategy. +loadBalancerBandwithInResourceWeight=1.0 + +# The BandWithOut usage weight when calculating new resource usage. +# It only takes effect in the ThresholdShedder strategy. +loadBalancerBandwithOutResourceWeight=1.0 + +# The CPU usage weight when calculating new resource usage. +# It only takes effect in the ThresholdShedder strategy. +loadBalancerCPUResourceWeight=1.0 + +# The heap memory usage weight when calculating new resource usage. +# It only takes effect in the ThresholdShedder strategy. +loadBalancerMemoryResourceWeight=1.0 + +# The direct memory usage weight when calculating new resource usage. +# It only takes effect in the ThresholdShedder strategy. +loadBalancerDirectMemoryResourceWeight=1.0 + +# Bundle unload minimum throughput threshold (MB), avoiding bundle unload frequently. +# It only takes effect in the ThresholdShedder strategy. +loadBalancerBundleUnloadMinThroughputThreshold=10 + +### --- Replication --- ### + +# Enable replication metrics +replicationMetricsEnabled=true + +# Max number of connections to open for each broker in a remote cluster +# More connections host-to-host lead to better throughput over high-latency +# links. +replicationConnectionsPerBroker=16 + +# Replicator producer queue size +replicationProducerQueueSize=1000 + +# Duration to check replication policy to avoid replicator inconsistency +# due to missing ZooKeeper watch (disable with value 0) +replicationPolicyCheckDurationSeconds=600 + +# Default message retention time +defaultRetentionTimeInMinutes=0 + +# Default retention size +defaultRetentionSizeInMB=0 + +# How often to check whether the connections are still alive +keepAliveIntervalSeconds=30 + +### --- WebSocket --- ### + +# Enable the WebSocket API service in broker +webSocketServiceEnabled=true + +# Number of IO threads in Pulsar Client used in WebSocket proxy +webSocketNumIoThreads=8 + +# Number of connections per Broker in Pulsar Client used in WebSocket proxy +webSocketConnectionsPerBroker=8 + +# Time in milliseconds that idle WebSocket session times out +webSocketSessionIdleTimeoutMillis=300000 + +# The maximum size of a text message during parsing in WebSocket proxy +webSocketMaxTextFrameSize=1048576 + +### --- Metrics --- ### + +# Enable topic level metrics +exposeTopicLevelMetricsInPrometheus=true + +# Time in milliseconds that metrics endpoint would time out. Default is 30s. +# Increase it if there are a lot of topics to expose topic-level metrics. +# Set it to 0 to disable timeout. +metricsServletTimeoutMs=30000 + +# Classname of Pluggable JVM GC metrics logger that can log GC specific metrics +# jvmGCMetricsLoggerClassName= + +### --- Broker Web Stats --- ### + +# Enable topic level metrics +exposePublisherStats=true + +# Enable expose the precise backlog stats. +# Set false to use published counter and consumed counter to calculate, this would be more efficient but may be inaccurate. +# Default is false. +exposePreciseBacklogInPrometheus=false + +### --- Deprecated config variables --- ### + +# Deprecated. Use configurationStoreServers +globalZookeeperServers= + +# Deprecated. Use brokerDeleteInactiveTopicsFrequencySeconds +brokerServicePurgeInactiveFrequencyInSeconds=60 + +### --- BookKeeper Configuration --- ##### + +ledgerStorageClass=org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage + +# The maximum netty frame size in bytes. Any message received larger than this will be rejected. The default value is 5MB. +nettyMaxFrameSizeBytes=5253120 + +# Size of Write Cache. Memory is allocated from JVM direct memory. +# Write cache is used to buffer entries before flushing into the entry log +# For good performance, it should be big enough to hold a substantial amount +# of entries in the flush interval +# By default it will be allocated to 1/4th of the available direct memory +dbStorage_writeCacheMaxSizeMb= + +# Size of Read cache. Memory is allocated from JVM direct memory. +# This read cache is pre-filled doing read-ahead whenever a cache miss happens +# By default it will be allocated to 1/4th of the available direct memory +dbStorage_readAheadCacheMaxSizeMb= + +# How many entries to pre-fill in cache after a read cache miss +dbStorage_readAheadCacheBatchSize=1000 + +flushInterval=60000 + +## RocksDB specific configurations +## DbLedgerStorage uses RocksDB to store the indexes from +## (ledgerId, entryId) -> (entryLog, offset) + +# Size of RocksDB block-cache. For best performance, this cache +# should be big enough to hold a significant portion of the index +# database which can reach ~2GB in some cases +# Default is to use 10% of the direct memory size +dbStorage_rocksDB_blockCacheSize= + +# Other RocksDB specific tunables +dbStorage_rocksDB_writeBufferSizeMB=4 +dbStorage_rocksDB_sstSizeInMB=4 +dbStorage_rocksDB_blockSize=4096 +dbStorage_rocksDB_bloomFilterBitsPerKey=10 +dbStorage_rocksDB_numLevels=-1 +dbStorage_rocksDB_numFilesInLevel0=4 +dbStorage_rocksDB_maxSizeInLevel1MB=256 + +# Maximum latency to impose on a journal write to achieve grouping +journalMaxGroupWaitMSec=1 + +# Should the data be fsynced on journal before acknowledgment. +journalSyncData=false + + +# For each ledger dir, maximum disk space which can be used. +# Default is 0.95f. i.e. 95% of disk can be used at most after which nothing will +# be written to that partition. If all ledger dir partions are full, then bookie +# will turn to readonly mode if 'readOnlyModeEnabled=true' is set, else it will +# shutdown. +# Valid values should be in between 0 and 1 (exclusive). +diskUsageThreshold=0.99 + +# The disk free space low water mark threshold. +# Disk is considered full when usage threshold is exceeded. +# Disk returns back to non-full state when usage is below low water mark threshold. +# This prevents it from going back and forth between these states frequently +# when concurrent writes and compaction are happening. This also prevent bookie from +# switching frequently between read-only and read-writes states in the same cases. +diskUsageWarnThreshold=0.99 + +# Whether the bookie allowed to use a loopback interface as its primary +# interface(i.e. the interface it uses to establish its identity)? +# By default, loopback interfaces are not allowed as the primary +# interface. +# Using a loopback interface as the primary interface usually indicates +# a configuration error. For example, its fairly common in some VPS setups +# to not configure a hostname, or to have the hostname resolve to +# 127.0.0.1. If this is the case, then all bookies in the cluster will +# establish their identities as 127.0.0.1:3181, and only one will be able +# to join the cluster. For VPSs configured like this, you should explicitly +# set the listening interface. +allowLoopback=true + +# How long the interval to trigger next garbage collection, in milliseconds +# Since garbage collection is running in background, too frequent gc +# will heart performance. It is better to give a higher number of gc +# interval if there is enough disk capacity. +gcWaitTime=300000 + +# Enable topic auto creation if new producer or consumer connected (disable auto creation with value false) +allowAutoTopicCreation=true + +# The type of topic that is allowed to be automatically created.(partitioned/non-partitioned) +allowAutoTopicCreationType=non-partitioned + +# Enable subscription auto creation if new consumer connected (disable auto creation with value false) +allowAutoSubscriptionCreation=true + +# The number of partitioned topics that is allowed to be automatically created if allowAutoTopicCreationType is partitioned. +defaultNumPartitions=1 + +### --- Transaction config variables --- ### +# Enable transaction coordinator in broker +transactionCoordinatorEnabled=false +transactionMetadataStoreProviderClassName=org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStoreProvider + +# Transaction buffer take snapshot transaction count +transactionBufferSnapshotMaxTransactionCount=1000 + +# Transaction buffer take snapshot interval time +# Unit : millisecond +transactionBufferSnapshotMinTimeInMillis=5000 + +### --- Packages management service configuration variables (begin) --- ### + +# Enable the packages management service or not +enablePackagesManagement=false + +# The packages management service storage service provide +packagesManagementStorageProvider=org.apache.pulsar.packages.management.storage.bookkeeper.BookKeeperPackagesStorageProvider + +# When the packages storage provider is bookkeeper, you can use this configuration to +# control the number of replicas for storing the package +packagesReplicas=1 + +# The bookkeeper ledger root path +packagesManagementLedgerRootPath=/ledgers + +### --- Packages management service configuration variables (end) --- ### diff --git a/mqtt-proxy/src/test/resources/mtls/cel-test.txt b/mqtt-proxy/src/test/resources/mtls/cel-test.txt new file mode 100644 index 000000000..107d2f1a3 --- /dev/null +++ b/mqtt-proxy/src/test/resources/mtls/cel-test.txt @@ -0,0 +1 @@ +CN=streamnative.io,OU=Pulsar\, Cloud,O=StreamNative\, Inc.,L=Mountain View\, 899 W Evelyn Ave,ST=California\0DAfter,C=US \ No newline at end of file diff --git a/mqtt-proxy/src/test/resources/mtls/client-cert.pem b/mqtt-proxy/src/test/resources/mtls/client-cert.pem new file mode 100644 index 000000000..192d68624 --- /dev/null +++ b/mqtt-proxy/src/test/resources/mtls/client-cert.pem @@ -0,0 +1,72 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: + 61:e6:1b:07:90:6a:4f:f7:cd:46:b9:59:1d:3e:1c:39:0d:f2:5e:01 + Signature Algorithm: sha256WithRSAEncryption + Issuer: CN = CARoot + Validity + Not Before: May 30 13:38:24 2022 GMT + Not After : May 27 13:38:24 2032 GMT + Subject: C = US, ST = CA, O = Apache, OU = Apache Pulsar, CN = superUser + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public-Key: (2048 bit) + Modulus: + 00:cd:43:7d:98:40:f9:b0:5b:bc:ae:db:c0:0b:ad: + 26:90:96:e0:62:38:ed:68:b1:70:46:3b:de:44:f9: + 14:51:86:10:eb:ca:90:e7:88:e8:f9:91:85:e0:dd: + b5:b4:14:b9:78:e3:86:d5:54:6d:68:ec:14:92:b4: + f8:22:5b:05:3d:ed:31:25:65:08:05:84:ca:e6:0c: + 21:12:58:32:c7:1a:60:a3:4f:d2:4a:9e:28:19:7c: + 45:84:00:8c:89:dc:de:8a:e5:4f:88:91:cc:a4:f1: + 81:45:4c:7d:c2:ff:e2:c1:89:c6:12:73:95:e2:36: + bd:db:ae:8b:5a:68:6a:90:51:de:2b:88:5f:aa:67: + f4:a8:e3:63:dc:be:19:82:cc:9d:7f:e6:8d:fb:82: + be:22:01:3d:56:13:3b:5b:04:b4:e8:c5:18:e6:2e: + 0d:fa:ba:4a:8d:e8:c6:5a:a1:51:9a:4a:62:d7:af: + dd:b4:fc:e2:d5:cd:ae:99:6c:5c:61:56:0b:d7:0c: + 1a:77:5c:f5:3a:6a:54:b5:9e:33:ac:a9:75:28:9a: + 76:af:d0:7a:57:00:1b:91:13:31:fd:42:88:21:47: + 05:10:01:2f:59:bb:c7:3a:d9:e1:58:4c:1b:6c:71: + b6:98:ef:dd:03:82:58:a3:32:dc:90:a1:b6:a6:1e: + e1:0b + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Subject Alternative Name: + DNS:localhost, IP Address:127.0.0.1 + Signature Algorithm: sha256WithRSAEncryption + 96:c2:23:2d:46:d0:3d:23:0e:ab:3d:b6:1e:31:96:00:eb:ae: + 17:ac:6e:c0:d4:1a:8d:0f:36:63:27:02:49:4e:24:cf:d3:80: + 88:3a:4f:d0:f1:e5:1c:df:2d:8a:ab:ae:8d:48:77:a0:d0:dc: + d5:80:1c:a1:3d:0d:49:64:bf:cb:39:84:c9:f3:5d:e0:2d:ba: + a0:f2:ac:03:85:44:a1:97:6b:0b:de:ed:a7:49:19:46:b2:18: + 49:21:62:43:52:36:6f:47:6c:21:6b:5e:41:85:28:71:6c:22: + 27:35:76:82:ed:ac:ad:d7:fa:9d:4c:7d:6f:44:7e:06:dd:8a: + 11:32:0c:d9:d0:f6:63:2a:40:ae:0d:5a:df:9e:d7:91:8a:db: + 2d:95:f3:19:f0:8f:1e:34:e3:b2:31:67:38:74:fd:3f:e6:49: + 5e:53:eb:88:ae:b1:45:71:0e:67:97:3c:99:4e:c7:ea:1e:02: + 67:b4:54:ef:4f:10:55:4a:70:c0:eb:41:e4:50:d4:48:5e:70: + c5:0f:79:f2:06:3d:35:ea:ce:5d:13:8e:14:65:fc:98:21:16: + 2d:5d:6d:f8:e0:6b:c7:c6:e4:8a:ca:c9:38:1f:93:27:86:28: + ef:96:e7:ad:6c:4a:9e:10:78:48:00:f4:4a:43:dc:87:1d:e3: + d3:39:53:68 +-----BEGIN CERTIFICATE----- +MIIDFDCCAfygAwIBAgIUYeYbB5BqT/fNRrlZHT4cOQ3yXgEwDQYJKoZIhvcNAQEL +BQAwETEPMA0GA1UEAwwGQ0FSb290MB4XDTIyMDUzMDEzMzgyNFoXDTMyMDUyNzEz +MzgyNFowVzELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMQ8wDQYDVQQKEwZBcGFj +aGUxFjAUBgNVBAsTDUFwYWNoZSBQdWxzYXIxEjAQBgNVBAMTCXN1cGVyVXNlcjCC +ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM1DfZhA+bBbvK7bwAutJpCW +4GI47WixcEY73kT5FFGGEOvKkOeI6PmRheDdtbQUuXjjhtVUbWjsFJK0+CJbBT3t +MSVlCAWEyuYMIRJYMscaYKNP0kqeKBl8RYQAjInc3orlT4iRzKTxgUVMfcL/4sGJ +xhJzleI2vduui1poapBR3iuIX6pn9KjjY9y+GYLMnX/mjfuCviIBPVYTO1sEtOjF +GOYuDfq6So3oxlqhUZpKYtev3bT84tXNrplsXGFWC9cMGndc9TpqVLWeM6ypdSia +dq/QelcAG5ETMf1CiCFHBRABL1m7xzrZ4VhMG2xxtpjv3QOCWKMy3JChtqYe4QsC +AwEAAaMeMBwwGgYDVR0RBBMwEYIJbG9jYWxob3N0hwR/AAABMA0GCSqGSIb3DQEB +CwUAA4IBAQCWwiMtRtA9Iw6rPbYeMZYA664XrG7A1BqNDzZjJwJJTiTP04CIOk/Q +8eUc3y2Kq66NSHeg0NzVgByhPQ1JZL/LOYTJ813gLbqg8qwDhUShl2sL3u2nSRlG +shhJIWJDUjZvR2wha15BhShxbCInNXaC7ayt1/qdTH1vRH4G3YoRMgzZ0PZjKkCu +DVrfnteRitstlfMZ8I8eNOOyMWc4dP0/5kleU+uIrrFFcQ5nlzyZTsfqHgJntFTv +TxBVSnDA60HkUNRIXnDFD3nyBj016s5dE44UZfyYIRYtXW344GvHxuSKysk4H5Mn +hijvluetbEqeEHhIAPRKQ9yHHePTOVNo +-----END CERTIFICATE----- diff --git a/mqtt-proxy/src/test/resources/mtls/client.cer b/mqtt-proxy/src/test/resources/mtls/client.cer new file mode 100644 index 000000000..36f70ea7d --- /dev/null +++ b/mqtt-proxy/src/test/resources/mtls/client.cer @@ -0,0 +1,18 @@ +-----BEGIN CERTIFICATE----- +MIIC9DCCAdygAwIBAgIUHqngM2NyphZKHyK/t8Vs1OoUL58wDQYJKoZIhvcNAQEL +BQAwETEPMA0GA1UEAwwGUk9PVENBMCAXDTI0MDgyMzEwNTgzNloYDzIxMjQwNzMw +MTA1ODM2WjARMQ8wDQYDVQQDDAZDTElFTlQwggEiMA0GCSqGSIb3DQEBAQUAA4IB +DwAwggEKAoIBAQC0S6AnsYUBJJP3ZiOqPdqvjW4nbslKvTYFo2tfLnobOakuSKyD +Iisx9FlUHLFMslL3QZ6mp/U8pmZU6YORWo/f6eElLuGtQPSVxqTEZH0v+GY8N8HA +XshvXmh7CSkGFzbKJ9vyAN2rZ/XrgEP3bBSQZxVSloLaNjV+lXzs3JaULxvQL+EJ +ef38RC//qI7qPflaNveIpnaCpG+Rx8QnFDYeyi8BDS2PdeKwLzj4aXaW5qjoBC3v +qk9/XLqxMXTAX8Ty32E7HrgxhG0mA48gYg2T/Ba8RPykNGvM/cncRgC+B0IJJ1jY +XAgdg/C5Xsz7DveWeezWibripMQN0UrkTjcLAgMBAAGjQjBAMB0GA1UdDgQWBBQY +djFGcYoRFXb7lyZkoFqQJnML1DAfBgNVHSMEGDAWgBSXAIfV5mlQg8lagBoWOfYa +lQ2JZzANBgkqhkiG9w0BAQsFAAOCAQEAiATbrV3/uIuIJQbXBssuVOlTcUWXPAHf +bFGz31NgPnb0za2ApoJ+912orSxSAvlG10g+2Z34iW8+bciH8e1DF+cPQKVg0lkm +jaMQO1cUVw6e2aRHagIMvgEwcz+PqVJoLvWWp5sjqnlafu/ZuXjzeyefuFbxD3kI +EAuSp4juklHrjLZbDulUgGuodKnJ/plzRLKUYoKArdmCAulZRmxcKBw6oYjQWo3A +6lLLHgqaV2g2RuAQFP6qCTMGEWXu4F8ZWJC6vV0zEDMh6QKJdNH1RShbsWlfIxsW +TU6Pswt9EyDIo2Wd72n/sAC8pFxvM8tfhFsAOihHB1XBb2YhtNCORQ== +-----END CERTIFICATE----- diff --git a/pom.xml b/pom.xml index c95faa726..ee82464b0 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,9 @@ pom - mqtt-impl + mqtt-common + mqtt-proxy + mqtt-broker tests diff --git a/scripts/build.sh b/scripts/build.sh index 6cdfd76d2..212eb97b2 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -28,5 +28,5 @@ ASSETS_DIR=release mkdir $ASSETS_DIR mvn clean install -DskipTests -Dmaven.wagon.http.retryHandler.count=3 -mv mqtt-impl/target/pulsar-protocol-handler-mqtt-*.nar ./$ASSETS_DIR +mv mqtt-broker/target/pulsar-protocol-handler-mqtt-*.nar ./$ASSETS_DIR cp README.md ./$ASSETS_DIR/pulsar-protocol-handler-mqtt-readme.md \ No newline at end of file diff --git a/tests/pom.xml b/tests/pom.xml index 64897485d..ec8729eda 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -91,7 +91,7 @@ copy protocol handler - diff --git a/tests/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/AdapterChannelTest.java b/tests/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/AdapterChannelTest.java index 83e1239d8..f8c4ba206 100644 --- a/tests/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/AdapterChannelTest.java +++ b/tests/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/AdapterChannelTest.java @@ -22,11 +22,11 @@ import io.netty.handler.codec.mqtt.MqttMessageBuilders; import io.streamnative.pulsar.handlers.mqtt.base.MQTTTestBase; import io.streamnative.pulsar.handlers.mqtt.common.MQTTCommonConfiguration; -import io.streamnative.pulsar.handlers.mqtt.common.adapter.AdapterChannel; -import io.streamnative.pulsar.handlers.mqtt.common.adapter.MQTTProxyAdapter; import io.streamnative.pulsar.handlers.mqtt.common.adapter.MqttAdapterMessage; import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyConfiguration; import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyService; +import io.streamnative.pulsar.handlers.mqtt.proxy.channel.AdapterChannel; +import io.streamnative.pulsar.handlers.mqtt.proxy.channel.MQTTProxyAdapter; import java.net.InetSocketAddress; import java.util.List; import java.util.Map; diff --git a/tests/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MqttProxyAdapterTest.java b/tests/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MqttProxyAdapterTest.java index d3e61e670..d935c9f5b 100644 --- a/tests/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MqttProxyAdapterTest.java +++ b/tests/src/test/java/io/streamnative/pulsar/handlers/mqtt/broker/MqttProxyAdapterTest.java @@ -19,9 +19,9 @@ import io.netty.channel.Channel; import io.streamnative.pulsar.handlers.mqtt.base.MQTTTestBase; import io.streamnative.pulsar.handlers.mqtt.common.MQTTCommonConfiguration; -import io.streamnative.pulsar.handlers.mqtt.common.adapter.MQTTProxyAdapter; import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyConfiguration; import io.streamnative.pulsar.handlers.mqtt.proxy.MQTTProxyService; +import io.streamnative.pulsar.handlers.mqtt.proxy.channel.MQTTProxyAdapter; import java.net.InetSocketAddress; import java.util.List; import java.util.Map;