1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00
This commit is contained in:
postmannen 2024-11-25 18:03:12 +01:00
parent b821aebc03
commit 9ea823293c
3 changed files with 42 additions and 27 deletions

View file

@ -596,6 +596,11 @@ func (p process) callHandler(message Message, thisNode string) []byte {
// executeHandler will call the handler for the Request type defined in the message. // executeHandler will call the handler for the Request type defined in the message.
func executeHandler(p process, message Message, thisNode string) { func executeHandler(p process, message Message, thisNode string) {
var err error var err error
if message.ToNode != "errorCentral" {
fmt.Printf("??????? DEBUG: executeHandler: got message: %v\n", message)
fmt.Printf("??????? DEBUG: executeHandler: got thisNode: %v\n", thisNode)
fmt.Printf("??????? DEBUG: executeHandler: got process: %+v\n", p)
}
// Check if it is a message to run scheduled. // Check if it is a message to run scheduled.
var interval int var interval int

View file

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"strings"
"sync" "sync"
"time" "time"
@ -369,7 +370,7 @@ func (p *processes) Start(proc process) {
// TODO: // TODO:
select { select {
case msg := <-proc.jetstreamOut: case msg := <-proc.jetstreamOut:
fmt.Printf("######## DEBUG: Publisher: received on <-proc.jetstreamOut: %v\n", msg) fmt.Printf("\n######## DEBUG: Publisher: received on <-proc.jetstreamOut: %v\n", msg)
// b, err := proc.messageSerializeAndCompress(msg) // b, err := proc.messageSerializeAndCompress(msg)
// if err != nil { // if err != nil {
// log.Fatalf("error: pfJetstreamPublishers: js failed to marshal message: %v\n", err) // log.Fatalf("error: pfJetstreamPublishers: js failed to marshal message: %v\n", err)
@ -381,6 +382,7 @@ func (p *processes) Start(proc process) {
subject := fmt.Sprintf("nodes.%v", msg.JetstreamToNode) subject := fmt.Sprintf("nodes.%v", msg.JetstreamToNode)
fmt.Printf("######## DEBUG: Publisher: before publish on subject: %v\n", subject) fmt.Printf("######## DEBUG: Publisher: before publish on subject: %v\n", subject)
_, err = js.Publish(proc.ctx, subject, b) _, err = js.Publish(proc.ctx, subject, b)
if err != nil { if err != nil {
log.Fatalf("error: pfJetstreamPublishers:js failed to publish message: %v\n", err) log.Fatalf("error: pfJetstreamPublishers:js failed to publish message: %v\n", err)
@ -415,42 +417,45 @@ func (p *processes) Start(proc process) {
log.Fatalf("error: jetstream new failed: %v\n", err) log.Fatalf("error: jetstream new failed: %v\n", err)
} }
stream, err := js.Stream(proc.ctx, "nodes") // stream, err := js.Stream(proc.ctx, "nodes")
if err != nil { // if err != nil {
log.Printf("error: js.Stream failed: %v\n", err) // log.Printf("error: js.Stream failed: %v\n", err)
} // }
// stream, err := js.CreateOrUpdateStream(proc.ctx, jetstream.StreamConfig{ stream, err := js.CreateOrUpdateStream(proc.ctx, jetstream.StreamConfig{
// Name: "nodes", Name: "nodes",
// Description: "nodes stream", Description: "nodes stream",
// Subjects: []string{"nodes.>"}, Subjects: []string{"nodes.>"},
// // Discard older messages and keep only the last one. // Discard older messages and keep only the last one.
// MaxMsgsPerSubject: 1, MaxMsgsPerSubject: 10,
// }) })
if err != nil { if err != nil {
log.Printf("error: js.Stream failed: %v\n", err) log.Printf("error: js.Stream failed: %v\n", err)
} }
// Check for more subjects via flags to listen to, and if defined prefix all // Check for more subjects via flags to listen to, and if defined prefix all
// the values with "nodes." // the values with "nodes."
////filterSubjectValues := []string{ fmt.Println("-------------------------------------------------------")
//// fmt.Sprintf("nodes.%v", proc.server.nodeName), fmt.Printf(" DEBUG: start consumer: proc.server.nodeName: %v\n", proc.server.nodeName)
//// //"nodes.all", fmt.Println("-------------------------------------------------------")
////} filterSubjectValues := []string{
////fmt.Printf("--- DEBUG: consumer: filterSubjectValues: %v\n", filterSubjectValues) fmt.Sprintf("nodes.%v", proc.server.nodeName),
//"nodes.all",
}
fmt.Printf("--- DEBUG: consumer: filterSubjectValues: %v\n", filterSubjectValues)
//// Check if there are more to consume defined in flags/env. // Check if there are more to consume defined in flags/env.
//if proc.configuration.JetstreamsConsume != "" { if proc.configuration.JetstreamsConsume != "" {
// splitValues := strings.Split(proc.configuration.JetstreamsConsume, ",") splitValues := strings.Split(proc.configuration.JetstreamsConsume, ",")
// for i, v := range splitValues { for i, v := range splitValues {
// filterSubjectValues[i] = fmt.Sprintf("nodes.%v", v) filterSubjectValues[i] = fmt.Sprintf("nodes.%v", v)
// } }
//} }
consumer, err := stream.CreateOrUpdateConsumer(proc.ctx, jetstream.ConsumerConfig{ consumer, err := stream.CreateOrUpdateConsumer(proc.ctx, jetstream.ConsumerConfig{
Name: "nodes_processor", Name: "nodes_processor",
Durable: "nodes_processor", Durable: "nodes_processor",
//FilterSubjects: filterSubjectValues, FilterSubjects: filterSubjectValues,
}) })
if err != nil { if err != nil {
log.Fatalf("error: create or update consumer failed: %v\n", err) log.Fatalf("error: create or update consumer failed: %v\n", err)

View file

@ -446,6 +446,11 @@ func (s *server) directSAMSChRead() {
for i, sam := range sams { for i, sam := range sams {
processName := processNameGet(sams[i].Subject.name(), processKindSubscriberNats) processName := processNameGet(sams[i].Subject.name(), processKindSubscriberNats)
if processName == "" {
fmt.Printf("error: processName was empty, sams[%v] was: %#v\n", i, sams[i])
os.Exit(1)
}
s.processes.active.mu.Lock() s.processes.active.mu.Lock()
p := s.processes.active.procNames[processName] p := s.processes.active.procNames[processName]
s.processes.active.mu.Unlock() s.processes.active.mu.Unlock()