-
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 625b269
Showing
9 changed files
with
310 additions
and
39 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,60 @@ | ||
package main | ||
|
||
import ( | ||
"sync" | ||
|
||
"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" | ||
) | ||
|
||
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,61 @@ | ||
package main | ||
|
||
import ( | ||
"sync" | ||
|
||
"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" | ||
) | ||
|
||
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
Oops, something went wrong.