-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(source): Implement new source event
- Loading branch information
1 parent
a5219d9
commit 0e81997
Showing
10 changed files
with
315 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package rabbitmq | ||
|
||
type Config struct { | ||
UserName string `koanf:"username"` | ||
Password string `koanf:"password"` | ||
Host string `koanf:"host"` | ||
Port int `koanf:"port"` | ||
Vhost string `koanf:"vhost"` | ||
ReconnectSecond int `koanf:"reconnect_second"` | ||
} |
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,59 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/labstack/gommon/log" | ||
"github.com/ormushq/ormus/adapter/otela" | ||
"github.com/ormushq/ormus/config" | ||
"github.com/ormushq/ormus/destination/dconfig" | ||
"github.com/ormushq/ormus/pkg/channel" | ||
rbbitmqchannel "github.com/ormushq/ormus/pkg/channel/adapter/rabbitmq" | ||
"github.com/ormushq/ormus/pkg/encoder" | ||
"sync" | ||
) | ||
|
||
func main() { | ||
cfg := config.C() | ||
done := make(chan bool) | ||
wg := &sync.WaitGroup{} | ||
dbConfig := dconfig.RabbitMQConsumerConnection{ | ||
User: cfg.RabbitMq.UserName, | ||
Password: cfg.RabbitMq.Password, | ||
Host: cfg.RabbitMq.Host, | ||
Port: cfg.RabbitMq.Port, | ||
Vhost: cfg.RabbitMq.Vhost, | ||
ReconnectSecond: cfg.RabbitMq.ReconnectSecond, | ||
} | ||
bufferSize := cfg.Source.BufferSize | ||
numberInstants := cfg.Source.NumberInstants | ||
maxRetryPolicy := cfg.Source.MaxRetry | ||
eventName := cfg.Source.NewSourceEventName | ||
err := otela.Configure(wg, done, otela.Config{Exporter: otela.ExporterConsole}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
outputAdapter := rbbitmqchannel.New(done, wg, dbConfig) | ||
err = outputAdapter.NewChannel(eventName, channel.OutputOnly, bufferSize, numberInstants, maxRetryPolicy) | ||
if err != nil { | ||
panic(err) | ||
} | ||
outputChannel, err := outputAdapter.GetOutputChannel(eventName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
wg.Add(1) | ||
|
||
go func() { | ||
defer wg.Done() | ||
for msg := range outputChannel { | ||
m := encoder.DecodeNewSourceEvent(string(msg.Body)) | ||
log.Info(m.WriteKey) | ||
|
||
if err := msg.Ack(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
}() | ||
wg.Wait() | ||
} |
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,60 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/ormushq/ormus/adapter/otela" | ||
"github.com/ormushq/ormus/config" | ||
"github.com/ormushq/ormus/contract/go/source" | ||
"github.com/ormushq/ormus/destination/dconfig" | ||
"github.com/ormushq/ormus/pkg/channel" | ||
rbbitmqchannel "github.com/ormushq/ormus/pkg/channel/adapter/rabbitmq" | ||
"github.com/ormushq/ormus/pkg/encoder" | ||
"sync" | ||
) | ||
|
||
func main() { | ||
cfg := config.C() | ||
done := make(chan bool) | ||
wg := &sync.WaitGroup{} | ||
dbConfig := dconfig.RabbitMQConsumerConnection{ | ||
User: cfg.RabbitMq.UserName, | ||
Password: cfg.RabbitMq.Password, | ||
Host: cfg.RabbitMq.Host, | ||
Port: cfg.RabbitMq.Port, | ||
Vhost: cfg.RabbitMq.Vhost, | ||
ReconnectSecond: cfg.RabbitMq.ReconnectSecond, | ||
} | ||
bufferSize := cfg.Source.BufferSize | ||
numberInstants := cfg.Source.NumberInstants | ||
maxRetryPolicy := cfg.Source.MaxRetry | ||
testCount := 100 | ||
|
||
err := otela.Configure(wg, done, otela.Config{Exporter: otela.ExporterConsole}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
inputAdapter := rbbitmqchannel.New(done, wg, dbConfig) | ||
err = inputAdapter.NewChannel(cfg.Source.NewSourceEventName, channel.InputOnlyMode, bufferSize, numberInstants, maxRetryPolicy) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
inputChannel, err := inputAdapter.GetInputChannel(cfg.Source.NewSourceEventName) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for messageID := 0; messageID < testCount; messageID++ { | ||
msg := encoder.EncodeNewSourceEvent(&source.NewSourceEvent{ | ||
ProjectId: uuid.New().String(), | ||
OwnerId: uuid.New().String(), | ||
WriteKey: uuid.New().String(), | ||
}) | ||
inputChannel <- []byte(msg) | ||
|
||
} | ||
}() | ||
wg.Wait() | ||
} |
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
Oops, something went wrong.