You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bifromq.apache.org by po...@apache.org on 2026/05/09 05:28:39 UTC
(bifromq) branch main updated: Start RPC server for standalone MQTT broker (#251)
This is an automated email from the ASF dual-hosted git repository.
popduke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bifromq.git
The following commit(s) were added to refs/heads/main by this push:
new 6cee2f3c3 Start RPC server for standalone MQTT broker (#251)
6cee2f3c3 is described below
commit 6cee2f3c33ea6dd79a4f4a0146cb3a66397d9824
Author: liaodongnian <36...@qq.com>
AuthorDate: Sat May 9 13:28:34 2026 +0800
Start RPC server for standalone MQTT broker (#251)
Include MQTTBroker in the starter RPC server bootstrap condition so MQTT-only deployments expose their broker service. Add coverage for MQTT-only and API-only bootstrap behavior. #250
---
.../bifromq/starter/ServiceBootstrapper.java | 3 +-
.../bifromq/starter/ServiceBootstrapperTest.java | 94 ++++++++++++++++++++++
2 files changed, 96 insertions(+), 1 deletion(-)
diff --git a/build/build-bifromq-starter/src/main/java/org/apache/bifromq/starter/ServiceBootstrapper.java b/build/build-bifromq-starter/src/main/java/org/apache/bifromq/starter/ServiceBootstrapper.java
index a26e59b24..83d50db47 100644
--- a/build/build-bifromq-starter/src/main/java/org/apache/bifromq/starter/ServiceBootstrapper.java
+++ b/build/build-bifromq-starter/src/main/java/org/apache/bifromq/starter/ServiceBootstrapper.java
@@ -75,7 +75,8 @@ class ServiceBootstrapper {
public BootstrappedServices bootstrap() {
// If any of the services is present, we need to start the RPC server
- if (distServerOpt.isPresent()
+ if (mqttBrokerOpt.isPresent()
+ || distServerOpt.isPresent()
|| distWorkerOpt.isPresent()
|| inboxServerOpt.isPresent()
|| inboxStoreOpt.isPresent()
diff --git a/build/build-bifromq-starter/src/test/java/org/apache/bifromq/starter/ServiceBootstrapperTest.java b/build/build-bifromq-starter/src/test/java/org/apache/bifromq/starter/ServiceBootstrapperTest.java
new file mode 100644
index 000000000..18b915dd7
--- /dev/null
+++ b/build/build-bifromq-starter/src/test/java/org/apache/bifromq/starter/ServiceBootstrapperTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.bifromq.starter;
+
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+import org.apache.bifromq.apiserver.IAPIServer;
+import org.apache.bifromq.baserpc.server.IRPCServer;
+import org.apache.bifromq.baserpc.server.RPCServerBuilder;
+import org.apache.bifromq.mqtt.IMQTTBroker;
+import org.apache.bifromq.starter.module.ServiceInjector;
+import org.mockito.InOrder;
+import org.testng.annotations.Test;
+
+public class ServiceBootstrapperTest {
+ @Test
+ public void mqttBrokerStartsRpcServer() {
+ ServiceInjector serviceInjector = mock(ServiceInjector.class);
+ RPCServerBuilder rpcServerBuilder = mock(RPCServerBuilder.class);
+ IRPCServer rpcServer = mock(IRPCServer.class);
+ IMQTTBroker mqttBroker = mock(IMQTTBroker.class);
+ when(serviceInjector.getInstance(RPCServerBuilder.class)).thenReturn(rpcServerBuilder);
+ when(rpcServerBuilder.build()).thenReturn(rpcServer);
+
+ ServiceBootstrapper.BootstrappedServices services = new ServiceBootstrapper(
+ Optional.empty(),
+ Optional.of(mqttBroker),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ serviceInjector).bootstrap();
+
+ services.start();
+
+ InOrder startOrder = inOrder(rpcServer, mqttBroker);
+ startOrder.verify(rpcServer).start();
+ startOrder.verify(mqttBroker).start();
+
+ services.stop();
+
+ InOrder stopOrder = inOrder(mqttBroker, rpcServer);
+ stopOrder.verify(mqttBroker).close();
+ stopOrder.verify(rpcServer).shutdown();
+ }
+
+ @Test
+ public void apiServerOnlyDoesNotStartRpcServer() {
+ ServiceInjector serviceInjector = mock(ServiceInjector.class);
+ IAPIServer apiServer = mock(IAPIServer.class);
+
+ ServiceBootstrapper.BootstrappedServices services = new ServiceBootstrapper(
+ Optional.of(apiServer),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ Optional.empty(),
+ serviceInjector).bootstrap();
+
+ services.start();
+
+ verify(apiServer).start();
+ verify(serviceInjector, never()).getInstance(RPCServerBuilder.class);
+ }
+}