implement broker

This commit is contained in:
2025-12-04 18:00:43 +09:00
parent cb958834cb
commit 13d37881b9
7 changed files with 190 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
//go:build integration
package nats_test
import (
"fmt"
"testing"
"time"
"github.com/neatflowcv/seven-skies/internal/pkg/broker/nats"
"github.com/stretchr/testify/require"
)
func TestNewBroker(t *testing.T) {
broker, err := nats.NewBroker(
t.Context(),
"nats://127.0.0.1:4222",
"SEVEN_SKIES_TEST_STREAM",
[]string{
"SEVEN_SKIES_TEST_SUBJECT.>",
},
)
require.NoError(t, err)
t.Cleanup(func() {
broker.Close()
})
err = broker.Subscribe(t.Context(), "SEVEN_SKIES_TEST_DURABLE", func(topic string, message []byte) error {
fmt.Println(topic, string(message))
return nil
})
require.NoError(t, err)
err = broker.Publish(t.Context(), "SEVEN_SKIES_TEST_SUBJECT.data", []byte("hello"))
require.NoError(t, err)
time.Sleep(2 * time.Second)
}