fix: improve local Pulsar connectivity checks

This commit is contained in:
w1ndyb0y
2026-07-10 17:07:42 +08:00
parent 46be9f483f
commit 4191868f00
3 changed files with 23 additions and 12 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ tasks:
emu: emu:
desc: Create a virtual serial port pair (ttyS0 ↔ ttyS1) with socat desc: Create a virtual serial port pair (ttyS0 ↔ ttyS1) with socat
cmds: cmds:
- socat PTY,link=ttyS0 PTY,link=ttyS1 - socat PTY,link=/tmp/ttyS0 PTY,link=/tmp/ttyS1
silent: false silent: false
deps: deps:
+19 -6
View File
@@ -16,11 +16,14 @@ limitations under the License.
package cmd package cmd
import ( import (
"net"
"net/url"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.uber.org/zap" "go.uber.org/zap"
"it2000.com.cn/tele-recv/serial" "it2000.com.cn/tele-recv/serial"
"it2000.com.cn/tele-recv/storage" "it2000.com.cn/tele-recv/storage"
"it2000.com.cn/tele-recv/transport"
) )
// testCmd represents the test command // testCmd represents the test command
@@ -56,13 +59,23 @@ func test() {
store.Close() store.Close()
} }
// Test Pulsar // Test the Pulsar endpoint without constructing a producer. The legacy Pulsar
sender, err := transport.NewPulsarSender(pulsarUrl, topic, name) // client used by the service is not compatible with newer Go runtimes on macOS.
endpoint, err := url.Parse(pulsarUrl)
if err != nil { if err != nil {
logger.Warn("pulsar connection failed (expected if no broker)", zap.Error(err)) logger.Warn("pulsar URL is invalid", zap.Error(err))
} else { } else {
logger.Info("pulsar ok") address := endpoint.Host
sender.Close() if endpoint.Port() == "" {
address = net.JoinHostPort(endpoint.Hostname(), "6650")
}
conn, err := net.DialTimeout("tcp", address, 3*time.Second)
if err != nil {
logger.Warn("pulsar connection failed (expected if no broker)", zap.Error(err))
} else {
conn.Close()
logger.Info("pulsar endpoint ok")
}
} }
} }
+1 -3
View File
@@ -6,17 +6,15 @@ serial:
#stopbits: 1 #stopbits: 1
lograw: true lograw: true
sqlite: sqlite:
file: telegram.db file: telegram.db
init: true init: true
socket: socket:
address: 127.0.0.1:6000 address: 127.0.0.1:6000
pulsar: pulsar:
url: pulsar://yzjc.gzzn.dev:6650 url: pulsar://localhost:6650
topic: telegram-raw topic: telegram-raw
name: serial-reader name: serial-reader