1、修改bug
This commit is contained in:
parent
753c4fe9c8
commit
e0eab082e6
2
ap.go
2
ap.go
|
@ -90,7 +90,7 @@ func (s *accessPoint) Connect() error {
|
||||||
// WriteWithTag will write data with specified tag, default transactionID is epoch time.
|
// WriteWithTag will write data with specified tag, default transactionID is epoch time.
|
||||||
func (s *accessPoint) WriteWithTag(tag uint8, data []byte) error {
|
func (s *accessPoint) WriteWithTag(tag uint8, data []byte) error {
|
||||||
f := frame.NewDataFrame()
|
f := frame.NewDataFrame()
|
||||||
f.SetCarriage(byte(tag), data)
|
f.SetCarriage(tag, data)
|
||||||
f.SetSourceId(s.client.ClientId())
|
f.SetSourceId(s.client.ClientId())
|
||||||
s.client.Logger().Debugf("%sWriteWithTag: tid=%s, source_id=%s, data[%d]=%# x",
|
s.client.Logger().Debugf("%sWriteWithTag: tid=%s, source_id=%s, data[%d]=%# x",
|
||||||
apLogPrefix, f.TransactionId(), f.SourceId(), len(data), frame.Shortly(data))
|
apLogPrefix, f.TransactionId(), f.SourceId(), len(data), frame.Shortly(data))
|
||||||
|
|
|
@ -11,11 +11,13 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
mq.InitOptions(hpds_node.WithAuth("token", "z1"))
|
mq.InitOptions(hpds_node.WithAuth("token", "06d36c6f5705507dae778fdce90d0767"))
|
||||||
defer mq.Close()
|
defer func(mq hpds_node.MessageQueue) {
|
||||||
|
_ = mq.Close()
|
||||||
|
}(mq)
|
||||||
|
|
||||||
// add Downstream mq
|
// add Downstream mq
|
||||||
mq.AddDownstreamMq(hpds_node.NewDownstreamMq(
|
_ = mq.AddDownstreamMq(hpds_node.NewDownstreamMq(
|
||||||
"mq-2",
|
"mq-2",
|
||||||
hpds_node.WithMqAddr("localhost:27187"),
|
hpds_node.WithMqAddr("localhost:27187"),
|
||||||
hpds_node.WithCredential("token:z2"),
|
hpds_node.WithCredential("token:z2"),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
name: mq-1
|
name: mq-1
|
||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
port: 27188
|
port: 27187
|
||||||
functions:
|
functions:
|
||||||
- name: echo-sf
|
- name: echo-sf
|
||||||
|
- name: capture-agent
|
||||||
|
|
|
@ -9,12 +9,18 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
mq := hpds_node.NewMqWithOptions(
|
mq := hpds_node.NewMqWithOptions(
|
||||||
"mq-2",
|
"mq-2",
|
||||||
hpds_node.WithMqAddr("localhost:27187"),
|
hpds_node.WithMqAddr("localhost:27188"),
|
||||||
hpds_node.WithAuth("token", "z2"),
|
hpds_node.WithAuth("token", "06d36c6f5705507dae778fdce90d0767"),
|
||||||
)
|
)
|
||||||
defer mq.Close()
|
defer func(mq hpds_node.MessageQueue) {
|
||||||
|
_ = mq.Close()
|
||||||
|
}(mq)
|
||||||
|
|
||||||
mq.ConfigWorkflow("mq_2.yaml")
|
err := mq.ConfigWorkflow("mq_2.yaml")
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Server load workflow error! %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// start mq service
|
// start mq service
|
||||||
log.Printf("Server has started!, pid: %d", os.Getpid())
|
log.Printf("Server has started!, pid: %d", os.Getpid())
|
||||||
|
|
|
@ -3,3 +3,4 @@ host: 0.0.0.0
|
||||||
port: 27188
|
port: 27188
|
||||||
functions:
|
functions:
|
||||||
- name: echo-sf
|
- name: echo-sf
|
||||||
|
- name: capture-agent
|
||||||
|
|
|
@ -8,18 +8,22 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
sf := hpds_node.NewStreamFunction(
|
sf := hpds_node.NewStreamFunction(
|
||||||
"echo-sf",
|
"hpds-ap",
|
||||||
hpds_node.WithMqAddr("localhost:27187"),
|
hpds_node.WithMqAddr("localhost:27188"),
|
||||||
hpds_node.WithObserveDataTags(0x33),
|
hpds_node.WithObserveDataTags(0x33),
|
||||||
hpds_node.WithCredential("token:z2"),
|
hpds_node.WithCredential("token:z2"),
|
||||||
)
|
)
|
||||||
defer sf.Close()
|
defer func(sf hpds_node.StreamFunction) {
|
||||||
|
_ = sf.Close()
|
||||||
|
}(sf)
|
||||||
|
|
||||||
// set handler
|
// set handler
|
||||||
sf.SetHandler(handler)
|
err := sf.SetHandler(handler)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("[sf] handler err=%v", err)
|
||||||
|
}
|
||||||
// start
|
// start
|
||||||
err := sf.Connect()
|
err = sf.Connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("[sf] connect err=%v", err)
|
log.Fatalf("[sf] connect err=%v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.hpds.cc/pavement/hpds_node"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
sf := hpds_node.NewStreamFunction(
|
||||||
|
"capture-agent",
|
||||||
|
hpds_node.WithMqAddr("localhost:27187"),
|
||||||
|
hpds_node.WithObserveDataTags(18),
|
||||||
|
hpds_node.WithCredential("06d36c6f5705507dae778fdce90d0767"),
|
||||||
|
)
|
||||||
|
defer sf.Close()
|
||||||
|
|
||||||
|
// set handler
|
||||||
|
sf.SetHandler(handler)
|
||||||
|
|
||||||
|
// start
|
||||||
|
err := sf.Connect()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("[sf] connect err=%v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
select {}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handler(data []byte) (byte, []byte) {
|
||||||
|
val := string(data)
|
||||||
|
log.Printf(">> [streamFunction] got tag=0x12, data=%s", val)
|
||||||
|
return 0x0, nil
|
||||||
|
}
|
14
mq.go
14
mq.go
|
@ -69,26 +69,26 @@ var _ MessageQueue = &messageQueue{}
|
||||||
func NewMqWithOptions(name string, opts ...Option) MessageQueue {
|
func NewMqWithOptions(name string, opts ...Option) MessageQueue {
|
||||||
options := NewOptions(opts...)
|
options := NewOptions(opts...)
|
||||||
zipper := createMessageQueueServer(name, options, nil)
|
zipper := createMessageQueueServer(name, options, nil)
|
||||||
zipper.ConfigMesh(options.MeshConfigURL)
|
_ = zipper.ConfigMesh(options.MeshConfigURL)
|
||||||
|
|
||||||
return zipper
|
return zipper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMq create a messageQueue instance from config files.
|
// NewMq create a messageQueue instance from config files.
|
||||||
func NewMq(conf string) (MessageQueue, error) {
|
func NewMq(conf string) (MessageQueue, error) {
|
||||||
config, err := config.ParseWorkflowConfig(conf)
|
confWf, err := config.ParseWorkflowConfig(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%s[ERR] %v", mqLogPrefix, err)
|
log.Errorf("%s[ERR] %v", mqLogPrefix, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// listening address
|
// listening address
|
||||||
listenAddr := fmt.Sprintf("%s:%d", config.Host, config.Port)
|
listenAddr := fmt.Sprintf("%s:%d", confWf.Host, confWf.Port)
|
||||||
|
|
||||||
options := NewOptions()
|
options := NewOptions()
|
||||||
options.MqAddr = listenAddr
|
options.MqAddr = listenAddr
|
||||||
zipper := createMessageQueueServer(config.Name, options, config)
|
zipper := createMessageQueueServer(confWf.Name, options, confWf)
|
||||||
// messageQueue workflow
|
// messageQueue workflow
|
||||||
err = zipper.configWorkflow(config)
|
err = zipper.configWorkflow(confWf)
|
||||||
|
|
||||||
return zipper, err
|
return zipper, err
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,9 @@ func (z *messageQueue) ConfigMesh(url string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer func() {
|
||||||
|
_ = res.Body.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
decoder := json.NewDecoder(res.Body)
|
decoder := json.NewDecoder(res.Body)
|
||||||
var configs []config.MeshMessageQueue
|
var configs []config.MeshMessageQueue
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package hpds_node
|
package hpds_node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"git.hpds.cc/Component/network"
|
"git.hpds.cc/Component/network"
|
||||||
"git.hpds.cc/pavement/hpds_node/config"
|
"git.hpds.cc/pavement/hpds_node/config"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -48,7 +47,12 @@ func (r *route) Add(connId string, name string, observeDataTags []byte) (err err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("SFN[%s] does not exist in config functions", name)
|
//return fmt.Errorf("SFN[%s] does not exist in config functions", name)
|
||||||
|
//如果不存在,自动增加
|
||||||
|
item := config.App{
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
|
r.functions = append(r.functions, item)
|
||||||
}
|
}
|
||||||
//去除只能订阅一次的问题
|
//去除只能订阅一次的问题
|
||||||
//LOOP:
|
//LOOP:
|
||||||
|
|
Loading…
Reference in New Issue