mirror of
https://github.com/fhmq/hmq.git
synced 2026-05-06 07:35:32 +00:00
allow bridge mq cost msg (#162)
This commit is contained in:
@@ -37,7 +37,8 @@ const (
|
||||
)
|
||||
|
||||
type BridgeMQ interface {
|
||||
Publish(e *Elements) error
|
||||
// Publish return true to cost the message
|
||||
Publish(e *Elements) (bool, error)
|
||||
}
|
||||
|
||||
func NewBridgeMQ(name string) BridgeMQ {
|
||||
|
||||
@@ -353,7 +353,7 @@ func (c *csvLog) logFilePrune() error {
|
||||
// Publish implements the bridge interface - it accepts an Element then checks to see if that element is a
|
||||
// message published to the admin topic for the plugin
|
||||
//
|
||||
func (c *csvLog) Publish(e *Elements) error {
|
||||
func (c *csvLog) Publish(e *Elements) (bool, error) {
|
||||
// A short-lived lock on c allows us to
|
||||
// get the Command topic then release the lock
|
||||
// This then allows us to process the command - which may
|
||||
@@ -372,7 +372,7 @@ func (c *csvLog) Publish(e *Elements) error {
|
||||
// If the outfile is set to "{NULL}" we don't do anything with the message - we just return nil
|
||||
// This feature is here to allow CSVLOG to be enabled/disabled at runtime
|
||||
if OutFile == "{NULL}" {
|
||||
return nil
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if e.Topic == CommandTopic {
|
||||
@@ -410,5 +410,5 @@ func (c *csvLog) Publish(e *Elements) error {
|
||||
// Push the message into the channel and return
|
||||
// the channel is buffered and is read by a goroutine so this should block for the shortest possible time
|
||||
c.msgchan <- e
|
||||
return nil
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (k *kafka) connect() {
|
||||
}
|
||||
|
||||
//Publish publish to kafka
|
||||
func (k *kafka) Publish(e *Elements) error {
|
||||
func (k *kafka) Publish(e *Elements) (bool, error) {
|
||||
config := k.kafkaConfig
|
||||
key := e.ClientID
|
||||
topics := make(map[string]bool)
|
||||
@@ -96,10 +96,10 @@ func (k *kafka) Publish(e *Elements) error {
|
||||
topics[config.DisconnectTopic] = true
|
||||
}
|
||||
default:
|
||||
return errors.New("error action: " + e.Action)
|
||||
return false, errors.New("error action: " + e.Action)
|
||||
}
|
||||
|
||||
return k.publish(topics, key, e)
|
||||
return false, k.publish(topics, key, e)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@ package bridge
|
||||
|
||||
type mockMQ struct{}
|
||||
|
||||
func (m *mockMQ) Publish(e *Elements) error {
|
||||
return nil
|
||||
func (m *mockMQ) Publish(e *Elements) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user