-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from ripienaar/64
(#64) support publishing data to the choria adapter framework
- Loading branch information
Showing
5 changed files
with
139 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package backplane | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/choria-io/go-choria/server/data" | ||
) | ||
|
||
// DataItem contains a single data message | ||
type DataItem struct { | ||
// Data is the raw data to publish | ||
Data []byte | ||
|
||
// Destination let you set custom NATS targets, when this is not set | ||
// the TargetAgent will be used to create a normal agent target | ||
Destination string | ||
|
||
// TargetAgent lets you pick where to send the data as a request | ||
TargetAgent string | ||
} | ||
|
||
// DataOutbox returns the channel to use for publishing data to the network from the backplane | ||
func (m *Management) DataOutbox() chan *DataItem { | ||
return m.outbox | ||
} | ||
|
||
// StartRegistration implements registration.RegistrationDataProvider | ||
func (m *Management) StartRegistration(ctx context.Context, wg *sync.WaitGroup, interval int, output chan *data.RegistrationItem) { | ||
for { | ||
select { | ||
case msg := <-m.outbox: | ||
output <- &data.RegistrationItem{ | ||
Data: &msg.Data, | ||
Destination: msg.Destination, | ||
TargetAgent: msg.TargetAgent, | ||
} | ||
case <-ctx.Done(): | ||
return | ||
} | ||
} | ||
} | ||
|
||
func (m *Management) startDataPublisher(ctx context.Context, wg *sync.WaitGroup) error { | ||
return m.cserver.RegisterRegistrationProvider(ctx, wg, m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters