fix: improve local Pulsar connectivity checks
This commit is contained in:
+2
-2
@@ -108,7 +108,7 @@ tasks:
|
||||
emu:
|
||||
desc: Create a virtual serial port pair (ttyS0 ↔ ttyS1) with socat
|
||||
cmds:
|
||||
- socat PTY,link=ttyS0 PTY,link=ttyS1
|
||||
- socat PTY,link=/tmp/ttyS0 PTY,link=/tmp/ttyS1
|
||||
silent: false
|
||||
|
||||
deps:
|
||||
@@ -147,4 +147,4 @@ tasks:
|
||||
- cp "{{.CONFIG}}" "{{.BUILD_DIR}}/"
|
||||
- cd "{{.BIN_DIR}}" && tar czvf "{{.APP}}.tar.gz" "{{.APP}}/" && mv "{{.APP}}.tar.gz" .
|
||||
- rm -rf "{{.BUILD_DIR}}"
|
||||
silent: false
|
||||
silent: false
|
||||
|
||||
+20
-7
@@ -16,11 +16,14 @@ limitations under the License.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
"it2000.com.cn/tele-recv/serial"
|
||||
"it2000.com.cn/tele-recv/storage"
|
||||
"it2000.com.cn/tele-recv/transport"
|
||||
)
|
||||
|
||||
// testCmd represents the test command
|
||||
@@ -56,16 +59,26 @@ func test() {
|
||||
store.Close()
|
||||
}
|
||||
|
||||
// Test Pulsar
|
||||
sender, err := transport.NewPulsarSender(pulsarUrl, topic, name)
|
||||
// Test the Pulsar endpoint without constructing a producer. The legacy Pulsar
|
||||
// client used by the service is not compatible with newer Go runtimes on macOS.
|
||||
endpoint, err := url.Parse(pulsarUrl)
|
||||
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 {
|
||||
logger.Info("pulsar ok")
|
||||
sender.Close()
|
||||
address := endpoint.Host
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(testCmd)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -6,17 +6,15 @@ serial:
|
||||
#stopbits: 1
|
||||
lograw: true
|
||||
|
||||
|
||||
sqlite:
|
||||
file: telegram.db
|
||||
init: true
|
||||
|
||||
|
||||
socket:
|
||||
address: 127.0.0.1:6000
|
||||
|
||||
pulsar:
|
||||
url: pulsar://yzjc.gzzn.dev:6650
|
||||
url: pulsar://localhost:6650
|
||||
topic: telegram-raw
|
||||
name: serial-reader
|
||||
|
||||
|
||||
Reference in New Issue
Block a user